Manage Protractor tests with a single Gulp task - angularjs

I'm trying to get e2e testing going with on my angular project using Gulp.
I'm able to get it working, but only if I manually launch a standalone selenium server using webdriver-manager start in a seperate terminal window.
Ideally I would like my gulp task to manage starting and stopping the server so as to not add more overhead for my team to run these tests.
I got set up following the instructions here:
https://github.com/mllrsohn/gulp-protractor
They describe 2 options for starting the selenium server. One is to set up a gulp task which appears to do the same thing as webdriver-manager start:
gulp.task('webdriver_standalone', require("gulp-protractor").webdriver_standalone);
This works, but not when I have my e2eTest task invoke it as a dependency. I have to run gulp webdriver_standalone in a seperate terminal window.
I cannot understand the other suggested option.
point to the selenium jar in the protractor config file
These instructions require a path to the selenium-server-standalone jar, in protractors node_modules (./node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar), but my node_modules/protractor/ directory does not have such a jar (or a selenium sub-directory at all)
The instructions for Running Protractor without a plugin seem to have the same problem of having to run the selenium server in another terminal window.
Is there a way to get this set up so that a single gulp task starts the standalone server, runs the tests, and shuts it down with no other intervention?

When you run Protractor you have several options regarding Selenium WebDriver (remember that WebDriver is web-service written in Java):
Run with Protractor with remote (standalone) service. It can be either local or on different machine. If Selenium is on different machine then your web app should be publicly available, not just localhost. If you choose to use standalone Selenium service then you configure your config file/Gulp task with seleniumAddress option.
"Ask" Protractor to run Selenium for you. In this case Protractor will run Selenium WebDriver with the Jar file you provide in seleniumServerJar configuration.
Do not use Selenium WD. Use direct connect instead, which is compatible with Chrome and (probably) Firefox only.
In your case simply run:
./node_modules/protractor/bin/webdriver-manager update
It will download Selenium. Then point config to the right jar.

The easiest way to get this working locally is using a local Selenium Standalone jar, as Igor suggested in option #2. (It is pretty difficult to get gulp to run webdriver-manager start as a spawned child_process or async task.)
You can get that jar in your node_modules folder easily by using:
npm install selenium-server-standalone-jar --save-dev
Then, in your protractor.conf.js comment out or remove the seleniumAddress line and add a line for seleniumServerJar.
exports.config = {
seleniumServerJar: '../node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-2.47.1.jar',
//seleniumAddress: 'http://localhost:4444/wd/hub',
/* Lines below for completeness only, leave yours as is. */
framework: 'jasmine2',
specs: ['login-spec.js'],
multiCapabilities: [{
browserName: 'chrome',
browserName: 'firefox'
}]
};

Related

Occasional ChromeDriver error when using Cucumber.js --parallel option

I have a UI test framework written in Selenium WebDriver JS, with test scenarios in Cucumber.js. I'm having an occasional issue when running these tests in Chrome and using the experimental --parallel CLI option. I tend to use --parallel 5 to speed up the overall execution time of the tests and this works well in all other browsers than Chrome, where the tests will sometimes end suddenly with the message
Error: EADDRNOTAVAIL connect EADDRNOTAVAIL 127.0.0.1:60730 - Local (0.0.0.0:0)
At that point the browsers remain open but the Cucumber process ends.
I know the --parallel option is experimental but I can find no other mentions of this online so I want to make sure I'm not doing something stupid.
I'm using:
Chrome 73.0.3683.103
ChromeDriver 73.0.0
Cucumber 5.1.0
Selenium WebDriver 4.0.0-alpha.1
(installed from npm).
This is on macOS 10.14.4 if that makes a difference. I can replicate this on other machines with the same OS version too, have not got a Windows machine to hand to try.
I suggest instead of using Selenium WebDriver JS with Cucumber that you use Protractor with Cucumber. Protractor is a JS wrapper of selenium and there is a project that has already done all the hard work of combining cucumber and selenium. Protractor has built-in parallel functionality that was built to run parallel browser testing. Check out https://github.com/protractor-cucumber-framework/protractor-cucumber-framework
This was an issue in selenium-webdriver that is now fixed in master.

Elementor. How to make it use protractor.conf?

I started adding e2e tests into our project and it seems a few things changed since the last time I used Protractor. For example elementExplorer still useful, but Elementor is way more cooler.
In its the readme is says to launch it by running e.g.: webmanager start and then elementor http://localhost:3000.
But this way it ignores protractor.conf. And since I have a binary path for Chrome browser in that file, along with a logic for clearing cookies and logging into the app in onPrepare function, protractor has to know where the file is. But I can't find a way.
Starting protractor as usual via protractor protractor.conf.coffee and then elementor localhost:3000 not working either. It says "Unable to start a WebDriver session"
Yes, you should launch it by running webdriver-manager start, I use this to run the scripts: protractor script_file_conf.js since I save my scripts as javascript code in my repository. Remember that the conf file should have a reference to the script file.

Bamboo with selenium webdriver

Tools: Java, Selenium WebDriver, Maven, Git, Bamboo
I'm not sure how I can run my test-cases under Bamboo which are written by java and build by maven and stored into Git repository. Bamboo can't open a real browser (IE, Firefox, chrome..)
It's worked when I tried to use HTMLUnitdriver (headless browser) instead of a real browser, BUT the problem with HTMLUnitdriver it is not functioning well (actually, it can't run most of the test scenarios even the other browsers do flawlessly).
I've Google it but could not found any good information on how to do it.
I'll really appreciate any help.
You should not run any test on Bamboo server. CI server is not meant to run any tests on. It should only controls how the tests will be executed instead. There are multiple ways to handle this. Selenium Grid is highly recommended. See another thread here on same topic
Use BrowserStack to execute test scripts and download reports/results as part of build as an artefact.
Or specify an agent that has the browser you need to test on.
https://www.browserstack.com/automate

Appium with Protractor: Working with AngularJS Asynchronous Calls

My Hybrid android app is built with angularjs library with lots of Asynchronous calls all over. How can I integrate Appium with Protractor, so that I can check for complete page loadings including asynchronous calls and other data bindings. My app is developed and ported as APK and not browsed in a browser. Am able to execute my selenium scripts but asynchronous calls is the place where I have stuck.
Please help me.
As of now Protractor doesn't officially support appium configurations. However there is a help file that is available in Protractor docs. All you need to do is update your conf.js file to include the appium configurations and remember to start your appium server before you run the test script.
To your question, you need to have below points ready -
Start your avd
Install the .apk file in your avd that you will be invoking through appium
Start the appium server using command - appium &
Update your protractor conf.js file to include appium android/chrome configurations. More details about configurations can be found in the below link.
Here's the link to it - Protractor-Appium Setup

grunt-protractor-runner and Cross-Browser testing

I am able to successfully run test on chrome on my current set-up, however I am unable to add other browsers to my tests. I am using the grunt module 'grunt-protractor-runner' to run my e2e tests.
Having looked around I know the grunt-protractor-runner module does support multiCapabilities, so on the face of it I would expect the simple task of editing the target config file to include multiCapabilities and update chromeOnly to false.
Although I can pass multiCapabilities, I cannot however change the chromeOnly option to 'false' and get my tests to run successfully. My errors when passing Firefox and Chrome to multiCapabilities,
Running 2 instances of WebDriver[launcher] Runner Process Exited With Error Code: 8
------------------------------------
PID: 7812 (capability: chrome #1)
------------------------------------
Using the selenium server at http://localhost:4444/wd/hub
C:\Project\node_modules\protractor\node_modules\selenium- webdriver\lib\webdriver\promise.js:1702
throw error;
^
------------------------------------
PID: 6444 (capability: firefox #1)
------------------------------------
Using the selenium server at http://localhost:4444/wd/hub
C:\Project\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1702
throw error;
^
I am running my set-up on Windows 7, using grunt-protractor-runner 1.0.1, protractor 0.23.1, chromedriver 2.9, and selenium-server-standalone 2.41.0
It would seem that I've been able to resolve this problem - it related to not starting a standalone selenium server, which grunt-protractor-runner does not do on it's own.
The way around this is to either open a new console at the location of the protractor web-driver using webdriver-manager start --standalone and running the tests using grunt-protractor-runner as before; or as I am currently, using the grunt-protractor-webdriver module and including it within the grunt task to be called.
In my protractor.conf.js file I removed chromeOnly: true and added a multiCapabilities array of browsers.

Resources