I am trying to work PhantomJS with Protractor with the web application being hosted on https. I need to specify a cert in order for this to work. Here is my protractor config file:
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
// Spec patterns are relative to the location of this config.
specs: [
'spec/*.js',
'spec/**/*.js'
],
capabilities: {
browserName: 'phantomjs',
'phantomjs.cli.args':['--ssl-certificates-path=cert.p12','--ignore-ssl-errors=true']
},
// A base URL for your application under test. Calls to protractor.get()
// with relative paths will be prepended with this.
baseUrl: 'https://localhost:3000',
jasmineNodeOpts: {
onComplete: null,
isVerbose: false,
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 100000
}
};
The result from the terminal is just a lot of:
17:00:56.340 INFO - Executing: [execute script: return window.location.href;, []])
17:00:56.346 INFO - Done: [execute script: return window.location.href;, []]"
There seems to be an acceptSslCerts option that is pushed into the logs but I have no idea how to set it:
[INFO - 2014-09-30T21:00:56.239Z] Session [df2bf1e0-48e4-11e4-a415-8755c19a8d30] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"1.9.7","driverName":"ghostdriver","driverVersion":"1.1.0","platf orm":"mac-unknown-64bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
Protractor itself throws this error:
Error: Error while waiting for Protractor to sync with the page: {"message":"Can't find variable: angular"
Any ideas?
Related
When using chromedriver in a protractor script, to test an angular page, I obtain different results using "Headless" or "Normal" browser.
Actually, if I use a "repeater" locator, to display the items in the "empty" list, it returns that there are 5 items, but the "headless" chrome driver fails to render them. Look at the screenshots.
I'm using ChromeDriver 2.45, which supports Chrome Version 70 to 72, I have version 71.
My OS is Windows 10.
Protractor version 5.1.1
Angularjs version 1.5
Here's the configuration file:
exports.config = {
directConnect: true,
rootElement: 'html',
chromeDriver: 'C:\\srv\\build\\applications\\chromedriver\\chromedriver_win32\\chromedriver.exe',
getPageTimeout: 60000,
allScriptsTimeout: 60000,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome',
chromeOptions:{
args:["--headless"]
}
},
specs: [ 'features/*.feature' ],
baseUrl: '',
cucumberOpts: {
tags: '',
require: [ 'steps/*.spec.js' ],
monochrome: true,
strict: true,
plugin: "json"
},
};
Seems to problem is in the window size. By default, headless mode is not a fullscreen, so some elements are automatically moved and hidden (as when you try manually to resize the window)
Just add to your conf:
driver.manage().window().maximize();
Can you update args to
capabilities: {
...,
chromeOptions: {
args: ["--headless", "--disable-gpu", "--window-size=800x600"]
}
}
For the exact configuration mentioned i am able to automate headless with no issues.
Reference https://github.com/angular/protractor/blob/master/docs/browser-setup.md#using-headless-chrome
I created a Jenkins job to run Protractor tests at midnight.
For headless testing, I'm using PhantomJS browser because I can't install Xvfb (don't have the rights).
I'm running the Protractor tests through a Grunt task.
On my local machine (windows), the grunt job works fine, and the tests pass.
On the server, I'm getting
Failed: waiting for page to load for 10000ms
...
Failed: Error while waiting for Protractor to sync with the page: "window.angular is undefined. This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping. See http://git.io/v4gXM for details"
My protractor-headless.conf:
exports.config = {
directConnect: false,
capabilities: {
browserName: 'phantomjs',
'phantomjs.binary.path': require('phantomjs').path,
'phantomjs.cli.args': []
},
seleniumServerJar: require('selenium-server-standalone-jar').path,
framework: 'jasmine2',
specs: [
'./e2e/**/**.spec.js'
],
allScriptsTimeout: 30000,
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 200000,
isVerbose: true//,
//includeStackTrace : false
},
onPrepare: function() {
'use strict';
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'test-results',
filePrefix: 'xmloutput'
}));
}
};
And the Grunt Job:
protractor: {
options: {
configFile: 'src/test/javascript/protractor.conf.js',
keepAlive: true,
noColor: false,
verbose: true,
args: {
// Arguments passed to the command
}
},
headless: {
options: {
keepAlive: false,
configFile: 'src/test/javascript/protractor-headless.conf.js'
}
}
}
...
grunt.registerTask('e2e-test-headless', [
'protractor:headless'
]);
The test have access to the testing environment.
Any idea what can be the problem?
I have a protractor config file as follows and i use phantomjs to run the tests. It works when i use seleniumServerJar but fails when i use seleniumAddress (pointing to a hub) with a 'The driver executable does not exist' message! Is there any specific config to run phantomjs with selenium-hub?
exports.config = {
//Fails when i use this
//seleniumAddress:"http://selenium-hub.com:4659/wd/hub",
//Works when i use this selenium-standalone jar
seleniumServerJar: '../../../node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar',
framework: 'cucumber',
specs: [
'features/*.feature'
],
capabilities: {
"browserName": "phantomjs",
"phantomjs.binary.path": require("phantomjs").path,
"phantomjs.ghostdriver.cli.args": ["--loglevel=DEBUG"]
},
baseUrl: '',
rootElement: 'body',
resultJsonOutputFile: 'src/test/report.json',
cucumberOpts: {
require: 'features/steps/*_steps.js',
}
};
I'm trying to get my config file to the point where I don't have to go to the mac terminal and type webdriver-manager start. Is it possible to have the config file do that? I have listed my code below to give you idea what I have set up. I just don't know if it is possible. Let me know. I am on a macbook pro.
exports.config = {
seleniumServerJar: './selenium/selenium-server-standalone-2.45.1.jar',
seleniumPort: null,
chromeDriver: './selenium/chromedriver.exe',
chromeDriver: null,
seleniumAddress: 'http://localhost:4444/wd/hub',
// ----- What tests to run -----
suites: {
CSRSmokeTest: '../smoke/deskTop/CSR.js'
DesktopSmokeTest: '../smoke/deskTop/**.js'
},
chromeOnly: false,
multiCapabilities: [
{
'browserName': 'chrome',
'chromeOptions': {
args: ['--lang=en',
'--window-size=1900,1200']
}
},
],
baseUrl: location + '/login/#/login',
rootElement: 'body',
onPrepare: function () {
browser.ignoreSynchronization = true;
browser.get(location + '/login/#/login');
},
params: {
user: {
//TEST******************************************
},
url: {
//some code
}
},
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: 6000000
}
};
If you just do not want to type in terminal you have several options:
Leave only seleniumServerJar option, and remove seleniumAddress. But starting Selenium everytime takes additionally 5-20 sec (depending on the hardware).
Use directConnect: true for Chrome. And then you do not need Selenium server at all. It works for me, but it is not fully portable solution.
Install Selenium somewhere on your server and leave it running forever. In this case your application should have publically accessible URL, so not just localhost.
For the moment, I have a basic angular app, generated by "generator-gulp-angular". In this project, I have 2 tests: 1 karma-test and 1 e2e-test (using protractor). The karma-test wil run without a problem, but with the other, I encounter some issues.
I'm trying to run selenium driver with phantomJS to execute the test, and in Chrome it works, in Firefox not (because of the upgrade), but trying to run the test on phantomJS wil fail. I have already downgraded my selenium stand-alone-server but now, selenium will give the error "driver info: driver.session: unknown". I'm using selenium 2.38 and phantom 1.9.x.
Can somebody tell me what to do? Should I adapt something in the conf-files of phantomJS node-module? Should I downgrade my phantomJS? ...
This is my protractor.conf.js:
exports.config = {
//directConnect: true,
seleniumAddress: 'http://localhost:4444/wd/hub',
baseUrl: 'http://localhost:9292',
rootElement: 'body',
// Capabilities to be passed to the webdriver instance.
capabilities: {
browserName: 'phantomjs',
'phantomjs.binary.path': 'C:/Users/--------/Documents/3de_Academiejaar/Stage/GitHub_Repos/proj_Jesper2/node_modules/phantomjs/bin/phantomjs',
},
specs: [paths.e2e + '/**/*.js'],
framework: 'jasmine',
jasmineNodeOpts: {
onComplete: function () {
},
isVerbose: true,
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 30000
}
};