Reputation: 1
I have a folder structure like this: project structure
And I am following this tutorial
My package.json file is like this:
{
"name": "node_cucumber_e2e",
"version": "1.0.1",
"description": "Sample E2E by Bill to learn cucumber and protractor",
"main": "index.js",
"scripts": {
"start": "node index.js",
"start-driver": "node .\\node_modules\\protractor\\bin\\webdriver-manager start",
"update-driver": "node .\\node_modules\\protractor\\bin\\webdriver-manager update",
"protractor": "node .\\node_modules\\protractor\\bin\\protractor configs/protractor.conf.js"
},
"keywords": [
"Sample_project",
],
"author": "",
"license": "MIT",
"devDependencies": {
"protractor": "^5.4.2"
}
}
I do following things:
npm run update-driver
npm run start-driver
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: [`../tests/e2e/specs/*.js`],
baseURL: 'http://localhost:8080/',
framework: 'jasmine',
}
Then when I tried to start protractor via npm run protractor
, the browser is open, however, it does not go to the url I specify and the console is this ==> output console
My spec js file is, hope someone could help me out
describe('Protractor Demo App', function() {
it ('should have a title', function() {
browser.get('https://juliemr.github.io/protractor-demo/');
expect(browser.getTitle()).toEqual('Super Calculator');
});
});
Upvotes: 0
Views: 94
Reputation: 440
Couple of things to be taken care of here:
The way you call the selenium driver to run the tests. There are other ways of doing it too. I prefer to do the directConnect = true
and go for headless
option to be able to debug better where you are facing an issue. Refer the below code snippet for protractor-conf.js
file:
export const config: Config = {
directConnect: true,
capabilities: {
'browserName': 'chrome',
chromeOptions: {
//args: [ "--headless", "--disable-gpu" ]
},
},
}
Since browser.get() & browser.getTitle()
is an asynchronous call that we are making, you can handle it promise returned using either the then()
or the await
for every async
call that is done.
I prefer using async/await
to handle such calls and I would rewrite spec
as:
describe('Protractor Demo App',() => {
it ('should have a title', async() => {
await browser.get('https://juliemr.github.io/protractor-demo/');
expect(await browser.getTitle()).toEqual('SuperCalculator');
});
});
IMO it helps to handle the promises more effectively while keeping my code clean. Lemme know if this works out for you!
Further improvements:
To update webdriver-manager use in your package.json
,
"webdriver-update": "./node_modules/protractor/bin/webdriver-manager update"
instead of npm run update-driver
.
Upvotes: 2