I'm currently working on an Electron app and I now want to integrate end-to-end testing with Protractor. I've reviewed the tutorials for Protractor and am now trying to adapt it to Electron. Since Electron runs as a standalone app, how do I do this?
It seems that Protractor stands-up a Selenium server that then tries to reach out to an available HTTP server and run tests such as click here, what url am I on, input this text, etc.
Therefore how would I go about allowing the selenium server access to the electron instance?
Anyway that's my mindset on the situation, any help is appreciated and feel free to correct any of my assumptions.
Adapting the instructions documented at Using Selenium and WebDriver, here is what you need to put into your protractor config (using directConnect, as an example):
exports.config = {
directConnect: true,
capabilities: {
browserName: "chrome",
chromeOptions: {
binary: '/Path-to-Your-App.app/Contents/MacOS/Atom' // < IMPORTANT!
},
},
// ...
}
(not tested)
alecxe's answer is mostly correct, but there's one slight inaccuracy with it.
binary should be nested under chromeOptions like so:
exports.config = {
directConnect: true,
capabilities: {
browserName: "chrome",
chromeOptions: {
binary: '/Path-to-Your-App.app/Contents/MacOS/Atom' // < IMPORTANT!
}
},
// ...
}
Related
I'm trying to test a mobile app written using Ionic and since Ionic is based on Angular, I want to write tests using Protractor and run the tests in mobile emulators using Saucelabs Appium. I invoke protractor using the command:
SAUCE_USERNAME=$(SAUCE_USERNAME) SAUCE_ACCESS_KEY=$(SAUCE_ACCESS_KEY) ./node_modules/.bin/protractor protractorConfig.js
But I get the following error:
UnknownError: Sauce Labs Authentication Error.
You used username 'None' and access key 'None' to authenticate, which are not valid Sauce Labs credentials.
My protractorConfig.js contains:
/* global exports */
/* global process */
exports.config = {
sauceUser: process.env.SAUCE_USERNAME,
sauceKey: process.env.SAUCE_ACCESS_KEY,
capabilities: {
appiumVersion: "1.0",
app: "sauce-storage:app.zip",
platformName: "iOS",
platformVersion: "7.1",
deviceName: "iPhone Simulator",
browserName: ""
},
allScriptsTimeout: 30000,
seleniumAddress: "http://" +
process.env.SAUCE_USERNAME + ":"+process.env.SAUCE_ACCESS_KEY+
"#ondemand.saucelabs.com:80/wd/hub",
specs: [
"spec/feature/*.js"
]
};
Why is Protractor/Saucelabs saying I'm not providing a user name or access key?
Edit: I based this question and my answer from information in one of the answers in Running e2e tests on Sauce Labs from Protractor on Travis. I made this question and answer in hopes that the information, which took a lot of google searching to find, would be more accessible to others who have the same issue.
Thanks to this other question I now know that you have to omit the 'seleniumAddress' from the configuration, otherwise Protractor will ignore your Saucelabs authentication. It will correctly generate the 'seleniumAddress' if omitted, though at this point I'm not sure how it knows how to do that.
I must be missing something here ...
I'm trying to use protractor to run e2e tests for my angular application. The configuration file is something along the lines of:
allScriptsTimeout: 11000,
specs: [
'src/**/*.e2e.js'
],
capabilities: {
browserName: 'firefox'
},
baseUrl: 'http://localhost:8000/app/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
isVerbose : true,
includeStackTrace : true,
defaultTimeoutInterval: 30000
}
The test looks something like this:
describe('example test', function() {
beforeEach(function () {
browser.get('index.html');
});
it('should test something trivial', function() {
expect(2).toEqual(2);
});
});
I'm using grunt to run it, with "grunt-protractor-runner".
When grunt gets to the protractor task, I see the following (running grunt with --verbose):
Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://172.17.113.30:53524/wd/hub
Then the firefox browser window opens, and resolves the URL correctly to: http://localhost:8000/app/index.html
However (and here's the question finally ...), firefox cannot find the page, i.e. I get the following error:
I tried running it with Chrome as well, but I get the same result.
My question is, what am I missing ?
In other words, who's job it is to get the angular app deployed at localhost:8000 ?
Is the deployment done by protractor/selenium/grunt, or do I need to deploy it on some webserver myself ?
Given that I can't find any question like mine online, I guess I'm missing something trivial here. Please help.
So, as discussed. Angular App needs to be deployed before executing any tests. Deploy the Angular app first and then start Testing using Protractor.
We are using protractor for Integration test. But for our chat application, we need two cookie isolated browser windows where we can switch between browsers and test the result.
Below is multiCapabilities part in my conf.js
multiCapabilities: [{
'browserName': 'firefox',
'maxInstances': 4,
'shardTestFiles': true
}, {
'browserName': 'chrome',
'maxInstances': 4,
'shardTestFiles': true
}],
And below is the code we used to invoke tests in single browser.
onPrepare: function() {
var app = require('./wrapper.js');
browser.driver.manage().timeouts().implicitlyWait(app.iwait);
browser.driver.manage().timeouts().setScriptTimeout(app.lwait);
browser.driver.manage().window().setPosition(0, 0);
browser.driver.manage().window().setSize(1280, 1000);
}
Now, I am unable to proceed further on how to launch a browser window on demand and do some actions with it and close browser window whenever is required. I have tried following steps mentioned here at https://github.com/angular/protractor/issues/381 but none of them worked and gave usage overview clearly.
Please help me on this.
I wrote an example that does exactly what you want (i.e. test an instant messenger) =)
See https://github.com/angular/protractor/blob/master/spec/interactionConf.js
and https://github.com/angular/protractor/blob/master/spec/interaction/interaction_spec.js#L51
To run the instant messenger test app that I'm testing against, checkout the protractor github project and run npm start
In the (now deprecated) angular scenario test runner, there was an option to create a runner.html page that would run the tests in an iFrame while reporting the progress, step-by-step, in the main page.
Is there any way to get a similar step-by-step log for protractor tests? It does not need to be in an html page (console or log file would be fine).
For that you can use the jasmine-spec-reporter for protractor. You'll have a visual feedback of all your passing and non-passing tests :
Easy to configure and looks really good in the console.
Hope this helps.
Since v1.0.0-rc2 you can see failures in real time:
In your protractor config, add a jasmineNodeOpts object with realtimeFailure option to true:
exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
specs: [
'e2e/**/*.js'
],
multiCapabilities: [
{'browserName': 'firefox'},
{'browserName': 'chrome'}
],
baseUrl: 'http://localhost:8000',
onPrepare: function() {},
jasmineNodeOpts: {
realtimeFailure: true
}
};
The full list of jasmine options is here: minijasminenode
And the well detailed reference config file for protractor here: referenceConf.js
I'm building a SaaS solution using AngularJS / JBOSS, hosted on a AWS EC2 instance; all our functionality is covered by unit and e2e tests. All the tests run fine locally. We can't figure out how to run them on AWS. Our AWS installation includes a headless CHROME, installed according to these instructions:
Steps to Reproduce
Set up chrome/firefox in linux based x86_64 EC2 instance
Launch webdriver-manager start
On a separate terminal window, launch protractor
Observed Behavior
1. The following error is shown on the webdriver terminal:
/usr/local/lib/node_modules/protractor/selenium/chromedriver: error while loading shared libraries: libgconf-2.so.4: cannot open shared object file: No such file or directory
06:41:15.140 WARN - Exception thrown
Expected Behavior
1. The protractor test is executed without errors
Additional resources:
1. Protractor configuration file
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['../test/e2e/**/*.js'],
// A base URL for your application under test. Calls to browser.get()
// with relative paths will be prepended with this.
baseUrl: 'http://localhost:8080/markodojo_solution/#/a3bc8692-5af4-4a4d-b21b-4e6f87dc2a32',
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
isVerbose: true,
defaultTimeoutInterval: 30000
},
//Options to output testreuslts in xml format
onPrepare: function() {
// The require statement must be down here, since jasmine-reporters
// needs jasmine to be in the global and protractor does not guarantee
// this until inside the onPrepare function.
require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmine.JUnitXmlReporter('xmloutput', true, true));
}
};
Thanks in advance for any assistance!
Go with Headless Chrome option
This greatly simplifies the workflow and having to use more system resources.
Follow the broad steps below:
Chrome install. Assuming you already have Chrome installed there. However if not following steps to install Chrome on linux EC2
Change your protractor options to something like below. The important thing is --headless. Additionally keep in mind that headless mode requires the browser size be specified upfront:-
chromeOptions: {
args: [ "--headless", "--disable-gpu", "--window-size=800,600" ]
}