How to run angular tests using protractor with safari under ubuntu? - selenium-webdriver

I want to know if there is a good way to test angular application using protractor with safari.
capabilities: [
{
browserName: 'safari',
seleniumAddress: 'http://localhost:4444/wd/hub',
},
],
I got this message when i tried to run my spec:
E/launcher - SessionNotCreatedError: Unable to create new service: SafariDriverService
I'm using ubuntu 18.04.5 / protractor 7.0.0 / webdriver-manager 12.1.7

Unfortunately you need MacOS host to run safari browser. Thats the only OS were Safari can be installed.

A workaround is https://www.browserstack.com/ with this tool you can control the real MacOS machine and any browser you want (including older versions)
When configured correctly, tests can be ran from any OS including Ubuntu
BUT the license is pricey
Try to lookup cheaper analogues, is you have budget for any license at all

Related

How to use safari technology preview in webdriver io tests (using wdio test runner)?

I tried running my tests on safari technology preview release 43 (Safari 11.1, WebKit 12605.1.12) using the below desired capabilities in wdio.conf.js.
capabilities: [{
browserName: 'safari',
'safari.options': {
technologyPreview: true
}
}]
Every time I run the tests, regular version of browser gets opened. Anybody facing similar issue?
Please find the logs below
[14:39:54] COMMAND POST "/wd/hub/session"
[14:39:54] DATA {"desiredCapabilities":{"javascriptEnabled":true,"locationContextEnabled":true,"handlesAlerts":true,"rotatable":true,"browserName":"safari","safari.options":{"technologyPreview":true},"loggingPrefs":{"browser":"ALL","driver":"ALL"},"requestOrigins":{"url":"http://webdriver.io","version":"4.6.2","name":"webdriverio"}}}
[14:39:55] INFO SET SESSION ID EE19F81D-B054-4926-8235-B64387250665
[14:39:55] RESULT {"applicationCacheEnabled":true,"rotatable":false,"databaseEnabled":true,"handlesAlerts":true,"version":"12604.3.5.1.1","cleanSession":true,"platform":"macOS","nativeEvents":true,"locationContextEnabled":false,"webStorageEnabled":true,"browserName":"safari","javascriptEnabled":true,"platformName":"macOS","cssSelectorsEnabled":true}
[14:39:56] COMMAND POST "/wd/hub/session/EE19F81D-B054-4926-8235-B64387250665/url"
It appears as if this is a feature that may not "yet" be supported by Selenium in their Safari Driver implementation.
After researching a little I came across this issue with notes from a few days ago.
https://github.com/SeleniumHQ/selenium/issues/4537
Near the bottom per a member of the Selenium Organization:
Reading "technologyPreview" setting from the node config file is not
yet implemented, it's an independent issue, we're working on this
feature.
dont use safari, but maybe you can open the binary in the same way how you can do it with chrome canary with define the .exe in the binary.
"browserName": "chromeCanary",
"platform": "MAC",
"chromeOptions": {
"binary": "/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary"
},

"Runtime.executionContextCreated has invalid 'context" error when i run Protractor

I am getting this below Error while i run my protractor. And below is the error as shown in my webstorm console.
"C:\Program Files (x86)\JetBrains\WebStorm 2016.2\bin\runnerw.exe"
"C:\Program Files\nodejs\node.exe"
c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\built\cli.js
C:\Users\x216526\workspace_Protractor\SWA_Protractor\conf.js
[17:59:58] I/direct - Using ChromeDriver directly... [17:59:58]
I/launcher - Running 1 instances of WebDriver [18:00:01] E/launcher -
session not created exception from unknown error:
Runtime.executionContextCreated has invalid 'context':
{"auxData":{"frameId":"9784.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=54.0.2824.0) (Driver info:
chromedriver=2.22.397933
(1cab651507b88dec79b2b2a22d1943c01833cc1b),platform=Windows NT
6.1.7601 SP1 x86_64) [18:00:01] E/launcher - SessionNotCreatedError: session not created exception from unknown error:
Runtime.executionContextCreated has invalid 'context':
{"auxData":{"frameId":"9784.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=54.0.2824.0) (Driver info:
chromedriver=2.22.397933
(1cab651507b88dec79b2b2a22d1943c01833cc1b),platform=Windows NT
6.1.7601 SP1 x86_64) at WebDriverError (c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:26:26)
at SessionNotCreatedError
(c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:307:26)
at Object.checkLegacyResponse
(c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:639:15)
at parseHttpResponse
(c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\http\index.js:538:13)
at
c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\http\index.js:472:11
at ManagedPromise.invokeCallback_
(c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1379:14)
at TaskQueue.execute_
(c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2913:14)
at TaskQueue.executeNext_
(c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2896:21)
at
c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2820:25
at
c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:639:7
From: Task: WebDriver.createSession() at Function.createSession
(c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:329:24)
at Driver
(c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\chrome.js:778:38)
at Direct.getNewDriver
(c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\built\driverProviders\direct.js:68:26)
at Runner.createBrowser
(c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\built\runner.js:187:43)
at
c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\built\runner.js:261:30
at _fulfilled
(c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:834:54)
at self.promiseDispatch.done
(c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch
(c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:796:13)
at
c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:556:49
at runSingle
(c:\Users\x216526\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:137:13)
[18:00:01] E/launcher - "process.on('uncaughtException'" error, see
launcher [18:00:01] E/launcher - Process exited with error code 199
Process finished with exit code 199
My config js look like below:
exports.config = {
directConnect: true, // Capabilities to be passed
//to the webdriver instance.
capabilities: { 'browserName': 'chrome', },
framework: 'jasmine2',
specs: ['./src/sli_sanitytests/San1_Check_
Sli_Homepage_is_Accessible_spec.js',
'./src/sli_sanitytests/San2_
Click_createButton_to_Open_Sli_CreateForm_page_spec.js',
'./src/sli_sanitytests/San3_
Create_Sli_reference_spec.js' ],
suites: {
smoke: ['./smoke/!*.spec.js'],
regression:['./regression/!*.spec.js'],
functional: ['./functional/!*.spec.js'],
all: ['./!*!/!*.spec.js'],
selected:['./functional/addcustomer.spec.js',
'./regression/openaccount.spec.js'],
},
// Options to be passed to Jasmine
jasmineNodeOpts: {
//onComplete will be called just before the driver quits.
onComplete: null,
// If true, display spec names.
isVerbose: true, // If true,print colors to the terminal.
showColors: true, // If true, include stack traces in
//failures.
includeStackTrace: true, // Default time to wait in ms
//before a test fails.
defaultTimeoutInterval: 80000
},
//enter code here
onPrepare:function() {
browser.ignoreSynchronization = true;
browser.driver.manage().window().maximize();
},
}
2016-10-13: ChromeDriver v2.24 has been released which supports Chrome v52-54. (Thanks #Anton)
2016-08-16: One of the recent updates to the Chrome Dev channel introduced a bug preventing ChromeDriver from properly starting. Having just worked around the same problem, I would suggest backing up your data and reverting to the Beta or Stable release channel of Chrome. See the Chrome Release Channels for more details on safely switching.
Alternatively, switching to the Dev version of ChromeDriver should also fix the issue. From a closed issue on the chromedriver project:
There are some Devtool changes in Chrome dev channel v54 which is not currently supported in Chromedriver stable v2.23.
You may want to use dev version of Chromedriver which has the fix. It can be downloaded from chromedriver…/continuous/….zip
Review the issue for the full link.
If the latest protractor is not having the latest chromedriver then to update it using webdriver-manager follow these below steps
enter latest chromedriver version in file config.json this file is present under path /node_modules/protractor/node_modules/webdriver-manager/built
optional (and change 'mac32' to 'mac64' in file 'chrome_driver.js' which is present under path /webdriver-manager/built/lib/binaries)
run webdriver-manager update in the console.
hint: To get the path of 'webdriver-manager' folder observe the console after command webdriver-manager update
Since I got the same issue and found this question, I'd like to add a bit more context: it is indeed a version problem between an 'old' chrome driver (2.22 in my case) and a 'newer' chrome release (54 in my case) like Sean answered.
However there is no need to fiddle manually with config files or downloads.
Instead just run
npm update protractor -g
To update protractor globally then
webdriver-manager update
To update the chrome driver. The newer chrome driver v2.25 is not yet included in the protractor package at the time of writing (you will get v2.24 instead) but it works fine with Chrome 54. Protractor is v4.09 at the time of writing. The same trick should work for future versions too!
After big battle with above issue i have found the solution for it. So please
don`t do anything.
First of all uninstall your chrome browser and reinstall it. That`s it protractor will not throw any such errors.
I even don`t know why this happened and for what reasons looks bit strange but yes the only solution is uninstall the chrome browser and reinstall it.
npm uninstall webdriver-manager -g
npm install webdriver-manager -g
I have the same problem with 2.24 version. In order to fix this bug download chromedriver.exe with version 2.25, it's available now by link https://sites.google.com/a/chromium.org/chromedriver/downloads
Try to reinstall webdriver-manager
npm uninstall webdriver-manager -g
npm install webdriver-manager -g
Issue was fixed for me after I installed webdriver-manager: 10.2.8
This is common issue, I faced it many times.
I use chromedriver in my selenium framework once in month and I usually get this type of error.
Follow below steps:
Unistall/Remove all existing chromedriver.
Install latest
chromedriver from official google site.
Set system path to chromedriver.exe folder (So you don't need to bother about setting the system path from code)
Restart the IDE (If already running)
ENJOY !
I updated to Chrome Driver 2.25 which fixed the problem for me. This is a simple update:
Download the latest version from: https://sites.google.com/a/chromium.org/chromedriver/downloads
Unzip the contents (it's one file "chromedriver.exe").
Copy that over your existing chromedriver.exe
For me that was at: \node_modules\protractor\selenium
That's it. I reran the tests and the pesky error went away.
First of all uninstall your chrome browser and reinstall it. That`s it protractor will not throw any such errors.
I even don`t know why this happened and for what reasons looks bit strange but yes the only solution is uninstall the chrome browser and reinstall it.
npm uninstall webdriver-manager -g npm install webdriver-manager -g

Can I make protractor use the IEDriverServer.exe webdriver-update installed in node_modules?

I'm writing acceptance tests for my angular web application project. They're run via protractor, and work just fine on chrome. But when I try to run them on Internet Explorer 11, I get a failure complaining that "The path to the driver executable must be set by the webdriver.ie.driver system propery". However, I have my project configured to download the IE driver to the same place as the chromedriver executable.
While I'm sure I could move the IE driver excutable to a folder stored in my PATH env variable, then every developer on the project would have to do the same or update their PATHs to point to the driver.
My question is - is there a simple configuration I'm missing to make this IE driver available to protractor just as Chrome's driver is?
My package.json:
{
//...
"scripts": {
"webdriver-update": "webdriver-manager update --ie",
"preacceptance-tests": "npm run webdriver:update -- --standalone",
"acceptance-tests": "protractor",
//...
}
My protractor.conf.js:
exports.config = {
baseUrl: 'http://localhost:3000/',
specs: [
'src/**/**test.ts',
'src/**/*test.ts'
],
capabilities: {
'browserName': 'internet explorer' //If I put chrome here, the tests pass
},
onPrepare: function() {
browser.ignoreSynchronization = true;
},
seleniumServerJar: "node_modules/protractor/selenium/selenium-server-standalone-2.51.0.jar",
useAllAngular2AppRoots: true
};
I run "npm run acceptance-tests", and chromedriver.exe and IEDriverServer.exe are downloaded to my node_modules/protractor/selenium folder. Protractor seems to be aware of the chromedriver, but why can't it see the IEDriverServer?
I can't seem to find an answer anywhere, other than manually pointing my PATH to this folder. It seems like I shouldn't have to if protractor can find the chromedriver...
As far as I know from having checked the Selenium source, there's only one workaround.
If an executable named IEDriverServer.exe exists in the current working directory (which is explicitly checked, and which you can query with process.cwd()), then that instance will be chosen and the PATH check bypassed (the error message is a little misleading).
You can follow the logic in the Selenium source here and here.

protractor fails to run with directConnect

I'm trying to run protractor by connecting directly to Chrome, not running Selenium. As the docs say, this is possible by setting the directConnect to true in the config file.
When I run protractor with directConnect: true, I get:
Using ChromeDriver directly...
[launcher] Running 1 instances of
WebDriver Error: spawn ENOENT
at errnoException (child_process.js:1001:11)
at Process.ChildProcess._handle.onexit (child_process.js:792:34) [launcher] Process exited with error code 1
If I run protractor without directConnect and instead specify my selenium url, everything runs fine.
I'm running Protractor version 1.6.1, Chrome version 41.0.2272.35 beta-m (64-bit), and Chromedriver version 2.13.0.
Update: While the solution below worked for me, after talking with a protractor dev I realized that if I run webdriver-manager update to install a local chromedriver, then I don't need to set the chromeDriver setting in my protractor config.
I had the same issue and solved it by varying the chromeDriver path setting in protractor-conf.js depending on whether I was on Windows or OSX/Linux.
Solution and writeup below assumes you are using chromedriver provided by npm install chromedriver. Also this solution worked with protractor 3.2.2 and chromedriver 2.21.2.
Protractor+chromedriver worked on OSX and Linux but I was getting ENOENT errors on Windows. I have filed an issue here and have also documented a workaround.
The issue (I think) is that childProcess.spawn has issues on Windows (see a list of issues here) and the node_modules/chromedriver/bin/chromedriver file will not correctly run when called via childProcess.spawn - likely because this file is not executable and Windows doesn't know to use the node binary to interpret the file.
The workaround is to provide the path to the windows executable when running on Windows. It is easy enough - though hackish - to vary the chromeDriver arg in protractor-conf.js as demonstrated below :
protractor-conf.js for all three OS:
var chromeDriverPath = process.platform === 'win32' ? 'node_modules/chromedriver/lib/chromedriver/chromedriver.exe' : 'node_modules/chromedriver/bin/chromedriver';
exports.config = {
directConnect: true,
chromeDriver: chromeDriverPath,
specs: [
'features/*.feature'
],
capabilities: {
browserName: 'chrome',
platform: 'ANY',
chromeOptions: {
args: ['--test-type']
}
}
}
Hope this helps.
ENOENT means Error, NO such ENTity, and relates to the file system.
Check you have the right path set in the chromeDriver option.
capabilities : {
chromeOptions: {
"debuggerAddress":"127.0.0.1:8088"
}
},
directConnect: true,
chromeDriver : "../bin/chromedriver_2.15.322448.exe"

Running Protractor tests on Browserstack Automate

I'm developing an AngularJS app and want to do end-2-end testing with Protractor. I would like to benefit from the suite of test browsers available at Browserstack and run the tests on Browserstack Automate instead of a local Selenium server.
How do I set up a system to run these tests?
NOTE: These instructions are only relevant for Protractor versions older than v3.0. Protractor 3.0 includes built-in support for Browserstack.
Prerequisites
You will need to have node and npm installed. Check your node version with node --version to ensure it is greater than v0.10.0.
Ready?
1. Install Protractor
Use npm to install Protractor globally with:
npm install -g protractor
If you get errors, you might need to run the above command as sudo.
Here's a more detailed tutorial for installing and using Protractor.
2. Install Browserstack Selenium web driver
EDIT: #elgalu pointed out in the comments this step is not necessary. Apparently the BrowserStackLocal tunnel (set up in step 4) is enough.
Following Browserstack's instructions for setting up node.js, install the seleniun web driver:
npm install -g browserstack-webdriver
3. Set up Protractor configuration
Create a protractor.conf.js file (see documentation for BrowserStack's supported capabilities):
exports.config = {
capabilities: {
'browserstack.user' : 'my_user_name',
'browserstack.key' : 'my_secret_key',
// Needed for testing localhost
'browserstack.local' : 'true',
// Settings for the browser you want to test
// (check docs for difference between `browser` and `browserName`
'browser' : 'Chrome',
'browser_version' : '36.0',
'os' : 'OS X',
'os_version' : 'Mavericks',
'resolution' : '1024x768'
},
// Browserstack's selenium server address
seleniumAddress: 'http://hub.browserstack.com/wd/hub',
// Pattern for finding test spec files
specs: ['test/**/*.spec.js']
}
Change your user name and secret key to the ones given on the Browserstack Automate page. If you're logged in to Browserstack, the instructions for setting up node.js will have you user and key substituted in the examples, and you can just copy-paste the javascript from there.
The same page also has a tool for generating the code for different test browser settings.
4. Download and run BrowserStackLocal
Download the BrowserStackLocal binary from the node.js instructions page.
Make the following changes to the command below, and run the binary to open the Browserstack tunnel required for testing.
Change your secret key in the command. Again, your_secret_key will be automatically substituted in the node.js guide, if you're logged in to Browserstack.
Change the port number to match the port you're hosting your AngularJS files at on localhost. The example uses port 3000.
./BrowserStackLocal your_secret_key localhost,3000,0
5. Run the tests
With everything ready for testing, run your tests:
protractor protractor.conf.js
You can watch the test run on Browserstack Automate and even see an updating live screenshot of the test browser.
Protractor from version 3.0.0 onwards has added inbuilt support for BrowserStack.
You simply need to add the following two parameters in your conf.js to launch the test on BrowserStack:
browserstackUser: '<username>'
browserstackKey: '<automate-key>'
Your username and automate key can be found here, after you have logged in to your account.
Hence, lets say you wish to run your test on Chrome 50 / OS X Yosemite, your conf.js should look something like this:
exports.config = {
specs: ['spec.js'],
browserstackUser: '<username>',
browserstackKey: '<automate-key>',
capabilities: {
browserName: 'Chrome',
browser_version: '50.0',
os: 'OS X',
os_version: 'Yosemite'
},
};
If you wish to run tests in parallel on different browser and OS combinations, you can use the multiCapabilities as given below:
exports.config = {
specs: ['spec.js'],
browserstackUser: '<username>',
browserstackKey: '<automate-key>',
multiCapabilities: [
{
browserName: 'Safari',
browser_version: '8.0',
os: 'OS X',
os_version: 'Yosemite'
},
{
browserName: 'Firefox',
browser_version: '30.0',
os: 'Windows',
os_version: '7'
},
{
browserName: 'iPhone',
platform: 'MAC',
device: 'iPhone 5S'
}
]
};
Some helpful links:
Code Generator - Helps you configure the capabilities to test on different various browser and OS combinations especially mobile devices.
Sample Github project for Protractor-BrowserStack - This should help you get started.
Hello! To only run the test against Browserstack, you may need to skip Step 4 from Niko Nyman answer, and in your conf.js you should have something like here's the one that I've used (+ report), then run Step 5:
var HtmlReporter = require('protractor-html-screenshot-reporter');
var reporter=new HtmlReporter({
baseDirectory: './protractor-result', // a location to store screen shots.
docTitle: 'Report Test Summary',
docName: 'protractor-tests-report.html'
});
// An example configuration file.
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://hub.browserstack.com/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome',
'version': '22.0',
'browserstack.user' : 'user_name',
'browserstack.key' : 'user_key',
'browserstack.debug' : 'true'
},
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['./specs/home_page_spec.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
},
onPrepare: function() {
jasmine.getEnv().addReporter(reporter);
}
};
We just wrote a blog post and open-source modules for this.
http://www.blog.wishtack.com/#!Cross-browser-testing-test-automation-with-Protractor-and-Browserstack/cuhk/554b3b5f0cf27313351f1163
wt-protractor-boilerplate
wt-protractor-runner
wt-protractor-utils

Resources