I am trying to run a test suite written in Protractor headlessly (using PhantomJS), but when I run the command 'phantomjs testSuiteFile.js' I get the error: ReferenceError: Can't find variable: browser. The browser variable is important in all of my tests so is there a way to allow phantomjs to find & use the browser object?
I also tried configuring my protractor config file to use phantomjs, I started selenium webdriver for phantomjs using the command recommended in the docs: phantomjs --webdriver=9134 and ran the config file with protractor protractor.conf.js. The config file is set to only run myTest.js, and I now get the error E/launcher - Error: Error: Cannot find module 'webpage'. But myTest.js works when I run phantomjs myTest.js
myTest.js:
var WebPage = require('webpage');
page = WebPage.create();
page.open('http://google.com');
page.onLoadFinished = function() {
page.render('googleScreenShot' + '.png');
phantom.exit();}
This is not how Protractor and PhantomJS work together. You need to execute protractor command from the command-line to have browser and other Protractor global variables initialized.
Related
I'm trying to launch chrome browser with "Modheader" extension using protractor by using the following in my conf.js
chromeOptions: {
args: [
'--load-extension=C:/Utilities/extension_2_2_4_0.crx'
],
But on running the test I get the following error:
Failed to load extension from ..... Manifest file is missing or unreadable
Is there any way to launch the browser with extension already installed OR is there any way to provide header with URL using protractor
baseUrl= www.abc.com
Header= 'name' : 'testuser'
I've seen this question before but nothing in the answers solved my problems. I am trying to do the protractor tutorial and here is the conf.js file:
// conf.js
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js']
}
Here is the spec.js file:
// spec.js
describe('Protractor Demo App', function() {
it('should have a title', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
expect(browser.getTitle()).toEqual('Super Calculator');
});
});
I am also getting ERROR100 on running another project, but for simplicity, I'm going to focus on this one project. Here is the error I'm getting:
E/configParser - Error code: 105
E/configParser - Error message: failed loading configuration file conf.js
E/configParser - C:\Workspace\ProtractorCalc\conf.js:6
I know this has to be something with my webdriver/selenium, but I don't know enough to debug it properly. I run webdriver-manager update and webdriver-manager start before running the conf.js file and when I do webdriver-manager start, it looks like it's running, but also prompts me to end webdriver-manager start in order to give me control of the command line:
I/e the last line when running it is "Selenium Server is up and running"
but then to be able to type protractor conf.js, I have to enter ctrl+c and I get this back:
Attempting to shut down selenium nicely
Staying alive until the Selenium Standalone process exists
events.js:163 throw er; //Unhandled 'error' event
Error: read ECONNRESET
at exports._errnoException (util.js:1050:11)
at TCP.onread(net.js.581:26)
Terminate batch job (Y/N)?
So is webdriver-manager kicking me out and that's why protractor's conf.js file is failing?
webdriver-manager start starts the webdriver, as you say, and it is running properly. However, when you press ctrl+c to "regain control", you're actually killing the process. It's at that point that webdriver stops, and that's why protractor won't run.
The easiest way to do this correctly is to open two command windows: run webdriver-manager start in the first one and protractor conf in the second.
First the logging refers to the conf.js file. When I look at your file I guess the problem is that you don't provide a capability to run the tests against. In other words, against what browser do you want to run your tests?
Here is an example project which has an example conf.js-file. If you change your file to this I think it should work without a problem
// An example configuration file.
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Framework to use. Jasmine is recommended.
framework: 'jasmine',
// Spec patterns are relative to the current working directory when
// protractor is called.
specs: ['spec.js'],
// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
I currently have nightwatch.js setup using the vue automated setup. That template is located here.
https://github.com/vuejs-templates/webpack/tree/master/template/test/e2e
Is it possible to run nightwatch assertions through the command line in a REPL like fashion that is available in webdriver.io? Here is a reference to the webdriver feature https://twitter.com/webdriverio/status/806911722682544128
Update, we have moved to using Cypress.io It has made us pretty happy
You can use nightwatch-repl package available on NPM.
https://www.npmjs.com/package/nightwatch-repl
// nightwatch.conf.js
var repl = require('nightwatch-repl');
module.exports = (function (settings) {
repl.init(settings);
...
...
return settings;
})(require('./nightwatch.json'));
Once you run your tests and invoke browser.repl()
you should see the following in your console
Running: Login to dashboard
Type in a command (eg: browser.function()) or type "quit" to exit
repl>
The Durandal Test Framework runs Jasmine tests within PhantomJS.
Where I'm implementing this for the first time I'm getting a lot of errors, and reading through these on the command prompt is proving to be very tedious.
If I load up the spec.html file in my web browser, it tells me that no specs were found:
Yet PhantomJS is able to find the specs with no problem:
Is there a way I can configure these Jasmine tests to run through my web browser and not through (or as well as) PhantomJS?
I've set up a new index.html file and have replaced the var runTests = ... section with a simple require() call:
require(['../test/specs/system.spec.js']);
Durandal's system.spec.js file is loaded in the browser, but Jasmine is still stating that no specs were found.
Jasmine's tests weren't being run because I wasn't telling it to re-execute. The solution to this was to simply re-execute by calling this within the require callback:
require(['../test/specs/system.spec.js'], function() {
jasmine.getEnv().execute();
});
Note: A drawback of this is that the 'no specs found' bar is still present and the 'raise exceptions' control on the re-executed specs doesn't appear to function:
I do the next test with nightwatch:
var page = browser.page.certificats();
page
.navigate()
.section.search
.waitForElementNotPresent('#loader', 1000);
.waitForElementPresent('#option', 2000)
On firefox and chrome, all work fine. With phantomJS, the test fails because it doesn't find the #option.
The #option element is build by some JS code.
I suspect a JS error but I can't get the JS error in console with phantomJS.
How can I get theses logs ?
Thanks.