I want to run protractor test using Firefox and phantomJS instead of chrome. However it will only run when I specify the 'chromeOnly: true' option and specify Chrome as the browser.
Otherwise it will crash and throw the error 'unable to start Webdriver Session'.
My protractor config:
'use strict';
var paths = require('./.yo-rc.json')['generator-gulp-angular'].props.paths;
// An example configuration file.
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
//seleniumServerJar: deprecated, this should be set on node_modules/protractor/config.json
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'firefox'
},
//chromeOnly: true,
baseUrl: 'http://localhost:8000/',
framework: 'jasmine',
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: [paths.e2e + '/**/*.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
}
};
The "chromeOnly" option means "connect directly to chrome" (vs. using a selenium server). When you remove that option, Protractor is expecting to talk to a selenium server to control a browser. See https://github.com/angular/protractor/blob/master/docs/server-setup.md.
Since Firefox now also supports a "direct connect" mode, the "chromeOnly" configuration option has been renamed to "directConnect". See https://github.com/angular/protractor/commit/3c048585ac811726d6c6d493ed6d43f6a3570bee
To use Firefox directly you can either leave the mis-named "chromeOnly" option set, or switch to "directConnect". Or, you can use Firefox via a selenium server (which just means you need to start the selenium server up, see the server-setup.md doc listed above).
Notice using phantomjs with protractor is disregarded.
Taken from http://angular.github.io/protractor/#/browser-setup
Add phantomjs to the driver capabilities, and include a path to the binary if using local installation:
capabilities: {
'browserName': 'phantomjs',
/*
* Can be used to specify the phantomjs binary path.
* This can generally be ommitted if you installed phantomjs globally.
*/
'phantomjs.binary.path': require('phantomjs').path,
/*
* Command line args to pass to ghostdriver, phantomjs's browser driver.
* See https://github.com/detro/ghostdriver#faq
*/
'phantomjs.ghostdriver.cli.args': ['--loglevel=DEBUG']
}
use
multiCapabilities : [
{
'browserName' : 'chrome',
'chromeOptions' : {
'binary' : 'chrome.exe',
'args' : [],
'extensions' : []
},
{
'browserName' : 'firefox',
'chromeOptions' : {
'binary' : 'path to firefox.exe',
'args' : [],
'extensions' : []
}...
}
Related
I have a Windows box and an Ubuntu box which I run my automated tests on. Currently, in my protractor.config.js file I have two seleniumAddress fields under my multiCapabilities: [{}] section and just comment out one or the other depending on which environment I would like to run in.
Is there a way to parameterize the seleniumAddress: so I can tell from my command line which environment to run in?
Something like this: gulp e2e --suite <suiteName> --baseUrl <URL>
--environment Windows
Here is my current multiCapabilities section from my protractor conf file:
multiCapabilities: [{
browserName: 'chrome',
// seleniumAddress: "URL to webdriver-manager Windows Box",
seleniumAddress: "URL to webdriver-manager Ubuntu Box",
platform: 'ANY',
version: 'ANY',
chromeOptions: {
args: ['--no-sandbox', '--test-type=browser', '--lang=en', '--window-size=1680,1050'],
prefs: {
'credentials_enable_service': false,
'profile': {
'password_manager_enabled': false
},
download: {
prompt_for_download: false,
directory_upgrade: true,
default_directory: 'C:\\downloads\\'
},
},
}
// shardTestFiles: true,
// maxInstances: 2
}],
Protractor is run on Node.js, so you should be able to pass an argument (a little more complicated), or easier, set an environmental variable:
Protractor conf snippet from the Protractor website with environmental variable logic added:
// Use the Windows selenium if the environmental variable IS_WINDOWS is set.
const seleniumServer = process.env.IS_WINDOWS ?
'https://path/to/windows-silenium' : 'https://path-to-default-selenium';
exports.config = {
// The address of a running selenium server.
seleniumAddress: seleniumServer,
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Spec patterns are relative to the configuration file location passed
// to protractor (in this example conf.js).
// They may include glob patterns.
specs: ['example-spec.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
}
};
I'm not quite sure what you would want to choose from (and I don't use gulp), but for the snippet above, you would probably use:
IS_WINDOWS=true gulp e2e --suite <suiteName> --baseUrl <URL>
The Story:
We have a rather huge end-to-end protractor test codebase. We have two configs - one is "local" - to run the tests in Chrome and Firefox using directConnect, and the other one is "remote" - to run tests on a remote selenium server - BrowserStack in our case.
Our "local" config is configured to run some tests in Chrome and some in Firefox - because we really cannot run some tests in Chrome - for instance, keyboard shortcuts don't work in Chrome+Mac. Running the tests that require using keyboard shortcuts in Firefox is a workaround until the linked chromedriver issue is resolved.
Here is the relevant part of the configuration:
var firefox_only_specs = [
"../specs/some_spec1.js",
"../specs/some_spec2.js",
"../specs/some_spec3.js"
];
exports.config = {
directConnect: true,
multiCapabilities: [
{
browserName: "chrome",
chromeOptions: {
args: ["incognito", "disable-extensions", "start-maximized"]
},
specs: [
"../specs/**/*.spec.js",
"../specs/**/**/*.spec.js",
"../specs/**/**/**/*.spec.js"
],
exclude: firefox_only_specs
},
{
browserName: "firefox",
specs: firefox_only_specs
}
],
// ...
};
The problem:
Now, the problem is that, if I'm debugging a single test, or want to run a single test - I'm marking it is as focused (via fdescribe/fit) - but protractor starts two driver sessions - one for Chrome and the other one for Firefox, using both configured capabilities:
Running "protractor:local" (protractor) task
[launcher] Running 2 instances of WebDriver
...
------------------------------------
[chrome #1] PID: 2329
[chrome #1] Using ChromeDriver directly...
[chrome #1] Spec started
...
------------------------------------
[firefox #2] PID: 2330
[firefox #2] Using FirefoxDriver directly...
[firefox #2] Spec started
...
The question:
Is there a way to tell protractor to use the only one capability that has a focused spec configured?
Using currently latest protractor 3.0.0.
Hope the question is clear. Let me know if you need any additional information.
I wonder if you can do something to wrap the it statements like:
onPrepare: function() {
browser.getCapabilities().then(function(caps) {
global.browserName = caps.caps_.browserName;
});
global.firefoxOnly = function(name, testFunction) {
if (browserName === 'firefox') {
return it(name, testFunction);
} else {
return xit(name, testFunction).pend('firefox only');
}
};
}
Then when you write a test, instead of it use something like:
describe('when I do something', function() {
firefoxOnly('it should do the right thing', function() {
doSomething();
expect(thing).toBe(right);
)};
});
I have no idea if this actually works, just throwing it out there. In fact, when I get back to my testing computer and try it out, I would be interested in adding a function like wip to use instead of xit to automatically pend my ATDD tests!
Is there a way to tell protractor to use the only one capability that has a focused spec configured?
According to the relevant github issue, it is not possible.
Seeing this Error message when I'm trying to run Intern tests from within my test files dir. the (relevant) structure of the dir is:
test
resources
rest
pickup.js
cashManagement.js
gitignore
intern.js
packages.js
packages.sample.js
...
The inter.js contains references to testFile1.js and testFile2.js in the suites section. I played a bit with the way these 2 files are referenced and got a "Failed to load module..." error. So I guess now that's solved and the ReferenceError is the one I need to figure out. I did go over the existing threads and nothing seems to solve my issue. The full error message is pasted below. I'll gladly supply more relevant info if needed.
Thanks,
Eran
***ReferenceError: document is not defined**
at /Applications/dojo-release-1.10.2/dojo/has.js:31:33
at execModule (/Users/eranbrand/src/MobilePosSolution/ovc-build/ovc-repo/src/test/node_modules/intern/node_modules/dojo/dojo.js:515:54)
at /Users/eranbrand/src/MobilePosSolution/ovc-build/ovc-repo/src/test/node_modules/intern/node_modules/dojo/dojo.js:504:12
at Array.map (native)
at execModule (/Users/eranbrand/src/MobilePosSolution/ovc-build/ovc-repo/src/test/node_modules/intern/node_modules/dojo/dojo.js:499:17)
at /Users/eranbrand/src/MobilePosSolution/ovc-build/ovc-repo/src/test/node_modules/intern/node_modules/dojo/dojo.js:582:7
at guardCheckComplete (/Users/eranbrand/src/MobilePosSolution/ovc-build/ovc-repo/src/test/node_modules/intern/node_modules/dojo/dojo.js:566:4)
at checkComplete (/Users/eranbrand/src/MobilePosSolution/ovc-build/ovc-repo/src/test/node_modules/intern/node_modules/dojo/dojo.js:574:27)
at onLoadCallback (/Users/eranbrand/src/MobilePosSolution/ovc-build/ovc-repo/src/test/node_modules/intern/node_modules/dojo/dojo.js:656:7)
at /Users/eranbrand/src/MobilePosSolution/ovc-build/ovc-repo/src/test/node_modules/intern/node_modules/dojo/dojo.js:761:5*
Here's the content of the intern.js file:
// Learn more about configuring this file at <https://github.com/theintern/intern/wiki/Configuring-Intern>.
// These default settings work OK for most people. The options that *must* be changed below are the
// packages, suites, excludeInstrumentation, and (if you want functional tests) functionalSuites.
serviceURL = "http://ovc.local:8080/POSMClient/json/process/execute/";
define(['./packages'], function(Packages) {
var returnValue = {
// Configuration options for the module loader; any AMD configuration options supported by the specified AMD loader
// can be used here
loader: {
packages: Packages.packages
},
// The port on which the instrumenting proxy will listen
proxyPort: 9000,
// A fully qualified URL to the Intern proxy
proxyUrl: 'http://localhost:9000/',
// Default desired capabilities for all environments. Individual capabilities can be overridden by any of the
// specified browser environments in the `environments` array below as well. See
// https://code.google.com/p/selenium/wiki/DesiredCapabilities for standard Selenium capabilities and
// https://saucelabs.com/docs/additional-config#desired-capabilities for Sauce Labs capabilities.
// Note that the `build` capability will be filled in with the current commit ID from the Travis CI environment
// automatically
capabilities: {
'selenium-version': '2.39.0'
},
// Browsers to run integration testing against. Note that version numbers must be strings if used with Sauce
// OnDemand. Options that will be permutated are browserName, version, platform, and platformVersion; any other
// capabilities options specified for an environment will be copied as-is
environments: [/*
{ browserName: 'internet explorer', version: '11', platform: 'Windows 8.1' },
{ browserName: 'internet explorer', version: '10', platform: 'Windows 8' },
{ browserName: 'internet explorer', version: '9', platform: 'Windows 7' },
{ browserName: 'firefox', version: '27', platform: [ 'OS X 10.6', 'Windows 7', 'Linux' ] },
{ browserName: 'chrome', version: '32', platform: [ 'OS X 10.6', 'Windows 7', 'Linux' ] },
{ browserName: 'safari', version: '6', platform: 'OS X 10.8' },
{ browserName: 'safari', version: '7', platform: 'OS X 10.9' }*/
],
// Maximum number of simultaneous integration tests that should be executed on the remote WebDriver service
maxConcurrency: 3,
// Whether or not to start Sauce Connect before running tests
useSauceConnect: false,
// Connection information for the remote WebDriver service. If using Sauce Labs, keep your username and password
// in the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables unless you are sure you will NEVER be
// publishing this configuration file somewhere
webdriver: {
host: 'localhost',
port: 4444
},
// The desired AMD loader to use when running unit tests (client.html/client.js). Omit to use the default Dojo
// loader
useLoader: {
'host-node': 'dojo/dojo',
'host-browser': 'node_modules/dojo/dojo.js'
},
// Non-functional test suite(s) to run in each browser
suites: [
"rest/pickup",
"rest/cashManagement"
],
// Functional test suite(s) to run in each browser once non-functional tests are completed
functionalSuites: [ /* 'myPackage/tests/functional' */ ],
// A regular expression matching URLs to files that should not be included in code coverage analysis
excludeInstrumentation: /^tests\//
}
return returnValue;
});
It looks like you're using the release build of Dojo, which assumes the document object will be available. To use that build you'll need to run intern with intern-runner or the browser client (client.html). If you'd prefer to run your tests with the node client (intern-client), you'll need to use the source distribution of Dojo or the dojo npm package.
Dojo 1.9 and Intern 1.7
I am having a problem with Intern in that it's reporting that require.on is not defined and my test suite is falling over.
This is only happening when trying to define a test that includes a widget. it looks like when the widget package is requried then it hits a line require.on("idle", onload) but fails because require.on is undefined.
As a test, I defined require.on and the test does not fall over.
All I can think of is that the version of dojo that intern ships with is interfering with the normal dojo module when requiring widgets using intern?
Here is a cut down version of my test:
define([
"intern!object",
"intern/chai!expect",
"dijit/form/Button"
],
function (
registerSuite,
expect,
Button) {
registerSuite({
name: "Simple test",
"failing test for demo" : function (){
expect(true).to.be.false;
}
});
});
Here is my configuration:
define({
// The port on which the instrumenting proxy will listen
proxyPort: 9000,
// A fully qualified URL to the Intern proxy
proxyUrl: 'http://localhost:9000/',
// Default desired capabilities for all environments. Individual capabilities can be overridden by any of the
// specified browser environments in the `environments` array below as well. See
// https://code.google.com/p/selenium/wiki/DesiredCapabilities for standard Selenium capabilities and
// https://saucelabs.com/docs/additional-config#desired-capabilities for Sauce Labs capabilities.
// Note that the `build` capability will be filled in with the current commit ID from the Travis CI environment
// automatically
capabilities: {
'selenium-version': '2.40.0'
},
// Browsers to run integration testing against. Note that version numbers must be strings if used with Sauce
// OnDemand. Options that will be permutated are browserName, version, platform, and platformVersion; any other
// capabilities options specified for an environment will be copied as-is
environments: [
{ browserName: 'chrome' }
],
// Maximum number of simultaneous integration tests that should be executed on the remote WebDriver service
maxConcurrency: 3,
// Whether or not to start Sauce Connect before running tests
useSauceConnect: false,
// Connection information for the remote WebDriver service. If using Sauce Labs, keep your username and password
// in the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables unless you are sure you will NEVER be
// publishing this configuration file somewhere
webdriver: {
host: 'localhost',
port: 4444
},
// Configuration options for the module loader; any AMD configuration options supported by the specified AMD loader
// can be used here
loader: {
// Packages that should be registered with the loader in each testing environment
packages: [
{
name: "dojo",
location: "libs/dojo"
}{
name: "dijit",
location: "libs/dijit"
},{
name: "unitTests",
location: "test/unit"
}
]
},
// Non-functional test suite(s) to run in each browser
suites: [ /* 'myPackage/tests/foo', 'myPackage/tests/bar' */
"unitTests/exampleTest"
],
// Functional test suite(s) to run in each browser once non-functional tests are completed
functionalSuites: [ /* 'myPackage/tests/foo', 'myPackage/tests/bar' */
],
// A regular expression matching URLs to files that should not be included in code coverage analysis
excludeInstrumentation: /^tests\//
});
Folder structure is:
app/
libs/
dojo
dijit
intern
test/
unit/
exampleTest.js
intern.js
I am running the test straight from the google chrome browser:
http://{webroot}/app/libs/intern/client.html?config=../test/intern
I do have some tests that run successfully but do not include any widgets.
Thanks for any help.
You are running an outdated version of Dojo 1.9 that expects that the AMD loader being used is the one that comes with Dojo 1.9, which is not the case in a default installation of Intern. You have two options:
Upgrade to Dojo 1.9.3 or later. (Recommended.)
Use the useLoader configuration option to point to dojo.js from your copy of Dojo 1.9:
define({
// ...
useLoader: {
'host-browser': 'path/to/dojo1.9/dojo.js'
}
})
First of all I'm a noob with e2e testing. What I've done is
installed protractor nmp install protractor
installed webdriver-manager
run webdriver-manager start from the directory where my angularjs app sits. it runs fine
run protractor tests/e2e/conf.js it also runs fine
However in few seconds it says Timed out waiting for page to load
Here are my files:
tests/e2e/conf.js:
// An example configuration file.
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['example_spec.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
}
};
tests/e2e/example_spec.js
var protr;
describe('addressBook homepage', function() {
var ptor;
beforeEach(function() {
ptor = protractor.getInstance();
});
it('should greet the named user', function() {
browser.get('/'); // <-- exception here
element(by.model('yourName')).sendKeys('Julie');
var greeting = element(by.binding('yourName'));
expect(greeting.getText()).toEqual('Hello Julie!');
});
});
I just can't understand where to define my webapp laypout/placement so protractor/webdriver knows which context to run.
With that setup protractor will be trying to navigate to "/". You need to either set the baseUrl property in the configuration file, or put an absolute url in the browser.get(). If all your tests are going to be on the same domain I'd recommend the first option.