protractor config file is not picking up the cucumber step definitions - protractor

i am new to protractor and cucumber framework. i followed the steps from protractor site and here https://semaphoreci.com/community/tutorials/getting-started-with-protractor-and-cucumber. i have a config file configured with cucumber framework options, feature file and step definition file. But when i run my cucumber-config file it does not recognize my step definitions and always throw an error. any help on this? below are my setup files.
//cucumber-config.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
browserName:'chrome'
},
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
specs: [
'./features/*.feature'
],
cucumberOpts: {
require: ['./features/step_definitions/*.steps.js'],
tags: [],
strict: true,
format: ["pretty"],
dryRun: false,
compiler: []
},
onPrepare: function () {
browser.manage().window().maximize();
}
};
//testone.feature
#features/test.feature
Feature: Running Cucumber with Protractor
Scenario: Protractor and Cucumber Test
Given I go to "https://angularjs.org/"
When I add "Be Awesome" in the task field
And I click the add button
Then I should see my new task in the list
//testone_steps.js
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
var expect = chai.expect;
module.exports = function() {
this.Given(/^I go to "([^"]*)"$/, function(site) {
browser.get(site);
});
this.When(/^I add "([^"]*)" in the task field$/, function(task) {
element(by.model('todoList.todoText')).sendKeys(task);
});
this.When(/^I click the add button$/, function() {
var el = element(by.css('[value="add"]'));
el.click();
});
this.Then(/^I should see my new task in the list$/, function(callback) {
var todoList = element.all(by.repeater('todo in todoList.todos'));
expect(todoList.count()).to.eventually.equal(3);
expect(todoList.get(2).getText()).to.eventually.equal('Do not Be Awesome')
.and.notify(callback);
});
};
when in run protractor cucumber-conf.js, i get the below error...
/opt/protractor_tests
➔ protractor cucumber.config.js
(node:3963) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[21:19:17] I/launcher - Running 1 instances of WebDriver
[21:19:17] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
Feature: Running Cucumber with Protractor
Scenario: Protractor and Cucumber Test
? Given I go to "https://angularjs.org/"
? When I add "Be Awesome" in the task field
? And I click the add button
? Then I should see my new task in the list
Warnings:
1) Scenario: Protractor and Cucumber Test - features/testone.feature:4
Step: Given I go to "https://angularjs.org/" - features/testone.feature:5
Message:
Undefined. Implement with the following snippet:
Given('I go to {stringInDoubleQuotes}', function (stringInDoubleQuotes, callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
2) Scenario: Protractor and Cucumber Test - features/testone.feature:4
Step: When I add "Be Awesome" in the task field - features/testone.feature:6
Message:
Undefined. Implement with the following snippet:
When('I add {stringInDoubleQuotes} in the task field', function (stringInDoubleQuotes, callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
3) Scenario: Protractor and Cucumber Test - features/testone.feature:4
Step: And I click the add button - features/testone.feature:7
Message:
Undefined. Implement with the following snippet:
When('I click the add button', function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
4) Scenario: Protractor and Cucumber Test - features/testone.feature:4
Step: Then I should see my new task in the list - features/testone.feature:8
Message:
Undefined. Implement with the following snippet:
Then('I should see my new task in the list', function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
1 scenario (1 undefined)
4 steps (4 undefined)
0m00.000s
[21:19:22] I/launcher - 0 instance(s) of WebDriver still running
[21:19:22] I/launcher - chrome #01 failed 1 test(s)
[21:19:22] I/launcher - overall: 1 failed spec(s)
[21:19:22] E/launcher - Process exited with error code 1
/opt/protractor_tests
➔
Updated With Execution error
[15:22:59] I/launcher - Running 1 instances of WebDriver
[15:22:59] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
Feature: Running Cucumber with Protractor
Scenario: Protractor and Cucumber Test
√ Given I go to "https://angularjs.org/"
√ When I add "Be Awesome" in the task field
√ And I click the add button
× Then I should see my new task in the list
Failures:
1) Scenario: Protractor and Cucumber Test - features\testone.feature:4
Step: Then I should see my new task in the list - features\testone.feature:8
Step Definition: features\step_definitions\testone.steps.js:22
Message:
Error: function timed out after 5000 milliseconds
at Timeout.<anonymous> (<local>\ProtractorTests\node_modules\cucumber\lib\user_code_runner.js:91:22)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
1 scenario (1 failed)
4 steps (1 failed, 3 passed)
0m05.049s
[15:23:19] I/launcher - 0 instance(s) of WebDriver still running
[15:23:19] I/launcher - chrome #01 failed 1 test(s)
[15:23:19] I/launcher - overall: 1 failed spec(s)
[15:23:19] E/launcher - Process exited with error code 1
error Command failed with exit code 1.

It's trying to use CucumberJS 2.0.0+ syntax - which is in development at the moment.
Either downgrade CucumberJS to 1.3.1 or below, or do this to your step definitions:
var chai = require('chai'),
expect = chai.expect,
chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
var {defineSupportCode} = require('cucumber');
defineSupportCode(({Given, When, Then}) => {
Given(/^I go to "([^"]*)"$/, function(site) {
return browser.get(site);
});
When(/^I add "([^"]*)" in the task field$/, function(task) {
return element(by.model('todoList.todoText')).sendKeys(task);
});
When(/^I click the add button$/, function() {
var el = element(by.css('[value="add"]'));
return el.click();
});
Then(/^I should see my new task in the list$/, function() {
var todoList = element.all(by.repeater('todo in todoList.todos'));
expect(todoList.count()).to.eventually.equal(3);
return expect(todoList.get(2).getText()).to.eventually.equal('Do not Be Awesome');
});
});
Which is the CucumberJS 2.0.0+ syntax
Edit
There are two ways of setting timeouts in CucumberJS 2.0.0
Default timeout
This is to set the default timeout for all of the scenarios that you have:
let scenarioTimeout = 200 * 1000,
{defineSupportCode} = require('cucumber');
defineSupportCode(({setDefaultTimeout}) => {
setDefaultTimeout(scenarioTimeout);
});
In this example, I am setting the scenario timeout to 200 seconds. You can change this to whatever you feel is appropriate.
Individual Steps
This is to set the timeout for a slow step:
When(/^I click the add button$/, {timeout: 60 * 1000}, function() {
var el = element(by.css('[value="add"]'));
return el.click();
});
In this example, the timeout is set to 60 seconds, you may want this larger or smaller, depending on what the step is doing.

In your config file:
require: ['./features/step_definitions/*.steps.js'],
But your file is: testone_steps.js, it should be: testone.steps.js
D'you see the difference? Just change _ to ., because in your config file you are using .

Related

Protractor tests are passing but didn't execute the tests

I am new to java script protractor cucumber framework.
I can see similar issue raised here an year ago but this was fixed in a protractor release an year ago as well. hence raising a new question.
I am using latest version of cucumber, protractor, protractor-cucumber-framework, chai, chai-as-promised. I am using visual studio code as editor.
Node Version is 6.11.4. Please look at the package.json below for all version details.
When I execute my tests, it finishes of in less than a second with a pass result but it just launches the browser and then doesn't do anything in the browser.
Please look at the files I am using and suggest me where is the problem. I am not sure whether this is a bus in the latest version of protractor.
protractor.conf.js:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['features/*.feature'],
getPageTimeout: 60000,
allScriptsTimeout: 500000,
baseURL: 'http://www.protractortest.org/testapp/ng1/#/form',
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome'
},
cucumberOpts: {
require: [ './features/step_definitions/*.steps.js' ],
tags: false,
profile: false,
'no-source': true
}
};
package.json:
{
"name": "protractor_test",
"version": "1.0.0",
"description": "",
"main": "protractor.conf.js",
"dependencies": {
"protractor": "^5.2.0",
"cucumber": "^3.1.0",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"#types/chai-as-promised": "^7.1.0",
"#types/cucumber": "^2.0.4",
"#types/protractor": "^4.0.0"
},
"devDependencies": {
"protractor-cucumber-framework": "^4.1.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
test.feature:
Feature: Running Cucumber with Protractor
As a user of Protractor
I should be able to use Cucumber
In order to run my E2E tests
Scenario: Login to myApp
Given I go to Login page
When I login with "username" and "pwd"
Then "You are logged in as ADMIN" is displayed
test.steps.js:
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
var {defineSupportCode} = require('cucumber');
var expect = chai.expect;
chai.use(chaiAsPromised);
defineSupportCode(function({Given, When, Then}) {
Given('I go to DSH Login page', function () {
browser.get("http://localhost/myapp");
expect(element(by.buttonText('Login')).isDisplayed()).to.eventually.equal(true);
});
When('I login with {string} and {string}', function (username, password) {
element(by.id('username')).sendKeys(username);
element(by.id('password')).sendKeys(password);
element(by.buttonText('Login')).click();
});
Then('{string} is displayed', function (headerText) {
expect(element(by.cssContainingText('ng-isolate-scope', headerText)).isDisplayed()).to.eventually.equal(true);
});
});
Console Output:
Debugging with legacy protocol because Node.js v6.11.4 was detected.
'C:\Program Files\nodejs\node.exe' --debug-brk=38084 --nolazy node_modules\protractor\bin\protractor protractor.conf.js
Debugger listening on [::]:38084
[16:48:02] I/launcher - Running 1 instances of WebDriver
[16:48:02] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
...
1 scenario (1 passed)
3 steps (3 passed)
0m00.015s
[16:48:05] I/launcher - 0 instance(s) of WebDriver still running
[16:48:05] I/launcher - chrome #01 passed
Selenium Chrome node console output:
Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 11099
Only local connections are allowed.
16:48:04.496 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession#1418ca00
16:48:04.496 INFO - Handler thread for session ed9fb79d586bc77176974953aaf98ef2 (chrome): Executing POST on /session/ed9fb79d586bc77176974953aaf98ef2/timeouts (handler: ServicedSession)
16:48:04.496 INFO - To upstream: {"script":500000}
16:48:04.496 INFO - To downstream: {"sessionId":"ed9fb79d586bc77176974953aaf98ef2","status":13,"value":{"message":"unknown error: 'ms' must be a double\n (Session info: chrome=60.0.3112.78)\n (Driver info: chromedriver=2.33.506120 (e3e
53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.3.9600 x86_64)"}}
16:48:04.512 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession#1418ca00
16:48:04.512 INFO - Handler thread for session ed9fb79d586bc77176974953aaf98ef2 (chrome): Executing POST on /session/ed9fb79d586bc77176974953aaf98ef2/timeouts (handler: ServicedSession)
16:48:04.512 INFO - To upstream: {"type":"script","ms":500000}
16:48:04.527 INFO - To downstream: {"sessionId":"ed9fb79d586bc77176974953aaf98ef2","status":0,"value":null}
16:48:05.010 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession#1418ca00
16:48:05.010 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession#1418ca00
16:48:05.010 INFO - Handler thread for session ed9fb79d586bc77176974953aaf98ef2 (chrome): Executing DELETE on /session/ed9fb79d586bc77176974953aaf98ef2 (handler: ServicedSession)
16:48:05.010 INFO - Handler thread for session ed9fb79d586bc77176974953aaf98ef2 (chrome): Executing POST on /session/ed9fb79d586bc77176974953aaf98ef2/url (handler: ServicedSession)
16:48:05.026 INFO - To upstream: {"url":"data:text/html,<html></html>"}
16:48:05.088 INFO - To downstream: {"sessionId":"ed9fb79d586bc77176974953aaf98ef2","status":0,"value":null}
16:48:05.088 INFO - Removing session org.openqa.selenium.remote.server.ServicedSession#1418ca00
16:48:05.138 INFO - To downstream: {"sessionId":"","status":0,"value":null}
16:48:05.138 INFO - To downstream: {"sessionId":"","status":6,"value":{"message":"no such session\n (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.3.9600 x86_64)"}}
Can you try using callback argument instead of relying on promises. If it works, then for entering username & password you can make use of Q package to resolve all the promises.
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
var {defineSupportCode} = require('cucumber');
var expect = chai.expect;
chai.use(chaiAsPromised);
defineSupportCode(function({Given, When, Then}) {
Given('I go to DSH Login page', function (callback) {
browser.get("http://localhost/myapp");
expect(element(by.buttonText('Login')).isDisplayed()).to.eventually.equal(true).and.notify(callback);
});
When('I login with {string} and {string}', function (username, password, callback) {
element(by.id('username')).sendKeys(username);
element(by.id('password')).sendKeys(password);
element(by.buttonText('Login')).click().then(function() {
callback();
});
});
Then('{string} is displayed', function (headerText, callback) {
expect(element(by.cssContainingText('ng-isolate-scope', headerText)).isDisplayed()).to.eventually.equal(true).notify(callback);
});
});
Since I am kind of getting used to the Javascript, I thought I will post what I am currently doing.
I have stopped using callbacks. Instead I use async and await so that the control waits for the asynchronous operation to be completed.
for example:
When('I login with {string} and {string}', async function (username, password) {
await element(by.id('username')).sendKeys(username);
await element(by.id('password')).sendKeys(password);
await element(by.buttonText('Login')).click();
});
Hope this helps someone.

unable to proceed protractor with cucumber

I am very new to cucumber framework, i started scripting cucumber with protractor, when i try to run the cucumber. conf.js file , I have seen the following error message
[17:07:35] I/launcher - Running 1 instances of WebDriver
[17:07:35] I/hosted - Using the selenium server at http://127.0.0.1:4444/wd/hub
UUUUU
Warnings:
1) Scenario: Login with valid userid and password # feature\test.feature:4
? Given I should be at the login page
Undefined. Implement with the following snippet:
Given('I should be at the login page', function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
? And I provide valid userid and password
Undefined. Implement with the following snippet:
Given('I provide valid userid and password', function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
? When I click on login button
Undefined. Implement with the following snippet:
When('I click on login button', function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
? Then I should be able to login inside the Gmail
Undefined. Implement with the following snippet:
Then('I should be able to login inside the Gmail', function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
? And The title of web page should be Gmail main page
Undefined. Implement with the following snippet:
Then('The title of web page should be Gmail main page', function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
1 scenario (1 undefined)
5 steps (5 undefined)
0m00.000s
[17:08:31] I/launcher - 0 instance(s) of WebDriver still running
[17:08:31] I/launcher - chrome #01 failed 1 test(s)
[17:08:31] I/launcher - overall: 1 failed spec(s)
[17:08:31] E/launcher - Process exited with error code 1
my conf.js file is
exports.config = {
seleniumAddress : 'http://127.0.0.1:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
framework: 'custom',
// path relative to the current config file
//frameworkPath: require.resolve('protractor-cucumber-framework'),
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome'
},
// Spec patterns are relative to this directory.
specs: [
'../feature/test.feature',
],
baseURL: 'http://localhost:8080/',
cucumberOpts: {
require: ['../feature/step_definitions/stepDefinitions.js'],
tags: false,
strict: true,
format: ["pretty"],
dryRun: false,
compiler: []
},
onPrepare: function () {
browser.manage().window().maximize();
}
};
if anyone come across this problem, please suggest me how to resolve this.

Protractor+Mocha fails suite with TypeError before browser loads SUT

Context
I'm exploring angular2 + angular-cli + typescript. My objective is to ensure that if I am doing an angular app or a node app in typescript I would be using the same testing technologies as legacy node apps that use mocha. To this end I am trying to reconfigure the angular-cli generated protractor.conf.js to use mocha instead of jasmine.
Question
How do you properly integrate angular-cli + mocha + protractor so that tests will execute with protractor actually providing the mocha specs useful browser/element/by components?
I've already changed the protractor.conf.js to use mocha and chai and the tests complete, however all interactions with protractor components fail i.e. element(by.css('app-root h1')).getText().
converted protractor.conf.js
exports.config = {
allScriptsTimeout: 11000, // The timeout for a script run on the browser.
specs: [
'./e2e/**/*.e2e-spec.ts' // pattern for the test specs
],
baseUrl: 'http://localhost:4200/', // base url of the SUT
capabilities: {
'browserName': 'chrome' // browser to use
},
directConnect: true, // selenium will not need a server, direct connet to chrome
framework: 'mocha', // Use mocha instead of jasmine
mochaOpts: { // Mocha specific options
reporter: "spec",
slow: 3000,
ui: 'bdd',
timeout: 30000
},
beforeLaunch: function() { // Do all the typescript
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
},
onPrepare: function() {}
};
Suspicion
It feels like the issue is that the suite is executing (and failing) before the the browser has even loaded the app. This could be the protractor/browser interaction which from what I understand should be agnostic to the spec that's being used. Perhaps this understanding is incorrect?
Example Source
I have a running example on GitHub which I am using to test and compare the conversion
Broken branch using mocha
Working master using jasmine
Investigation so far
Running protractor (via node) on the command line node node_modules\protractor\bin\protractor protractor.conf.js --stackTrace --troubleshoot shows us that the suite is configured and running with a truthy test, a skipped test, and the actual application tests
Suite results
We see that the truthy test is passing, the skipped test is skipped, and the application tests all fail with the same sort of error
1 passing
1 pending
5 failing
1) A descriptive test name that is irrelevant to the error:
TypeError: obj.indexOf is not a function
at include (node_modules\chai\lib\chai\core\assertions.js:228:45)
at doAsserterAsyncAndAddThen (node_modules\chai-as-promised\lib\chai-as-promised.js:293:29)
at .<anonymous> (node_modules\chai-as-promised\lib\chai-as-promised.js:271:25)
at chainableBehavior.method (node_modules\chai\lib\chai\utils\overwriteChainableMethod.js:51:34)
at assert (node_modules\chai\lib\chai\utils\addChainableMethod.js:84:49)
at Context.it (e2e\search\search.e2e-spec.ts:14:40)
at runTest (node_modules\selenium-webdriver\testing\index.js:166:22)
at node_modules\selenium-webdriver\testing\index.js:187:16
at new ManagedPromise (node_modules\selenium-webdriver\lib\promise.js:1067:7)
at controlFlowExecute (node_modules\selenium-webdriver\testing\index.js:186:14)
From: Task: A descriptive test name that is irrelevant to the error
at Context.ret (node_modules\selenium-webdriver\testing\index.js:185:10)
It appears that the TypeError would be caused because the app itself never seems to have to time to actually load in the browser before the suite is complete
--troubleshoot output
[09:26:33] D/launcher - Running with --troubleshoot
[09:26:33] D/launcher - Protractor version: 5.1.1
[09:26:33] D/launcher - Your base url for tests is http://localhost:4200/
[09:26:33] I/direct - Using ChromeDriver directly...
[09:26:36] D/runner - WebDriver session successfully started with capabilities Capabilities {
'acceptSslCerts' => true,
'applicationCacheEnabled' => false,
'browserConnectionEnabled' => false,
'browserName' => 'chrome',
'chrome' => { chromedriverVersion: '2.28.455520 (cc17746adff54984afff480136733114c6b3704b)',
userDataDir: 'C:\\Users\\abartish\\AppData\\Local\\Temp\\scoped_dir4596_5000' },
'cssSelectorsEnabled' => true,
'databaseEnabled' => false,
'handlesAlerts' => true,
'hasTouchScreen' => false,
'javascriptEnabled' => true,
'locationContextEnabled' => true,
'mobileEmulationEnabled' => false,
'nativeEvents' => true,
'networkConnectionEnabled' => false,
'pageLoadStrategy' => 'normal',
'platform' => 'Windows NT',
'rotatable' => false,
'takesHeapSnapshot' => true,
'takesScreenshot' => true,
'unexpectedAlertBehaviour' => '',
'version' => '56.0.2924.87',
'webStorageEnabled' => true }
[09:26:36] D/runner - Running with spec files ./e2e/**/*.e2e-spec.ts
Additional Info
Interestingly enough, if you run protractor with elementExplorer node node_modules\protractor\bin\protractor protractor.conf.js --stackTrace --troubleshoot --elementExplorer it will not run the tests but we do see the SUT resolve in the browser that gets launched. This I can't explain.
First off, I am not that familiar with Mocha. However, I can get your tests to pass. This is what you'll need to do:
Set your dependencies
It sometimes is great to roll with the latest and greatest dependencies. The latest chai-as-promised did not work for me. I once tried to update the Protractor dependencies to the latest version of chai and chai-as-promised and ran issues. I had to downgrade your dependencies and ended up working with:
"chai": "~3.5.0",
"chai-as-promised": "~5.3.0",
These are the same versions as the Protractor package.json.
Use the onPrepare plugin
Set chai-as-promised before Protractor runs the test:
onPrepare: function() {
let chai = require('chai');
let chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
global.chai = chai;
}
Edit the test:
Add or modify the following.
app.e2e-spec.ts
import {RootPage} from './root/root.po';
let expect = global["chai"].expect;
// change the following lines to have "eventually"
expect(page.getParagraphText()).to.eventually.contain('Car search POC');
// if you don't want to use "eventually"
page.getParagraphText().then(paragraph => {
expect(paragraph).to.contain('Car search POC');
});
root.e2e-spec.ts:
let expect = global["chai"].expect;
describe('Home page', () => {
// change the following lines to have "eventually"
expect(page.getParagraphText()).to.eventually.include('Car search POC');
expect(browser.getCurrentUrl()).to.eventually.include(homePage.uri());
home.e2e-spec.ts:
import {RootPage} from './root.po';
import {HomePage} from '../home/home.po';
import {WaitCondition} from '../wait.conditions';
let expect = global["chai"].expect;
// change the following lines to have "eventually"
expect(page.getParagraphText()).to.eventually.equal('Car search POC');
// This line will not work. getInnerHtml has been deprecated by both
// Protractor and selenium-webdriver.
//
// If you want to use something similar, do something like:
// let i = browser.executeScript("return arguments[0].innerHTML;", element(locator));
// This is noted in the CHANGELOG under the Protractor 5.0.0 release
expect(page.getListingContent()).to.exist;
search.e2e-spec.ts
import {SearchPage} from './search.po';
let expect = global["chai"].expect;
// change the following lines to have "eventually"
expect(page.getParagraphText()).to.eventually.contain('Car search POC');
Console output
Here is my results from running your test. Note that "will have content" fails because getInnerHtml() is not a valid.
angular-cli-seed App
✓ will do normal tests
✓ will display its title
Home page
✓ will display its title
- will have content
root page
✓ will display its title
✓ will redirect the URL to the home page
search page
✓ will display its title
6 passing (5s)
1 pending
This was a fun StackOverflow question to go through. It was easy to answer since you included a branch of what was not working. Happy testing!

gulp-protractor not able to execute test

I am not able to run the test using gulp-protractor task. It starts the standalone Selenium Server and launch the Chrome Browser but does nothing after that.
gulp.js
var gulp = require('gulp');
var gp = require('gulp-protractor');
var protractor = require("gulp-protractor").protractor;
var webdriver_standalone = require("gulp-protractor").webdriver_standalone;
gulp.task('protractor',function(cb) {
gulp.src(['./test/e2e/*.js'])
.pipe(protractor({
configFile: 'conf.js'
})).on('error', function(e) {
console.log(e)
}).on('end', cb);
})
conf.js
exports.config = {
//directConnect: true,
seleniumServerJar: './node_modules/protractor/selenium/selenium-server-standalone-2.48.2.jar',
specs: ['./test/e2e/*.js'],
baseUrl: http://url
Console output
[13:25:11] Starting 'protractor'...
Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://IP:64422/wd/hub
Started
.........*
Pending:
1) should be able to click on Company Name "ABC firm
No reason given
10 specs, 0 failures, 1 pending spec
Finished in 0.041 seconds
Shutting down selenium standalone server.
[launcher] 0 instance(s) of WebDriver still running
[launcher] chromeANY #1 passed
[13:25:17] Finished 'protractor' after 5.69 s
Please advice.
In gulpfile.js
var angularProtractor = require('gulp-angular-protractor');
gulp.task('test', function (callback) {
gulp
.src([__dirname+'/public/apps/adminapp/**/test/**_test.js'])
.pipe(angularProtractor({
'configFile': 'public/apps/adminapp/app.test.config.js',
'debug': false,
'args': ['--suite', 'adminapp'],
'autoStartStopServer': true
}))
.on('error', function(e) {
console.log(e);
})
.on('end',callback);
});
In config file
exports.config = {
baseUrl: 'http://localhost:8000/#/login',
framework:'jasmine',
seleniumServerJar : '../../../node_modules/selenium-standalone-jar/bin/selenium-server-standalone-2.45.0.jar',
suites: {
adminapp: [
'login/test/login_test.js',
'jobs/test/jobs-edit_test.js'
]
},
capabilities: {
browserName: 'chrome'
}
}
Its pretty easy and straight forward and also works for me.

Protractor & Cucumber. this.visit is not a function

I'm trying to experiment with protractor and cucumber to add some functional BDD testing to some of our webapps. Piecing together the scraps of information online related to this process, I've managed to piece together a very basic test but when I run the tests with protractor conf.js I get the following error
this.visit is not a function
I'm sure this is something I am doing fundamentally wrong but could someone show me the error of my ways, please?
The full console for this test reads:
Using the selenium server at http://192.168.12.100:4724/wd/hub
[launcher] Running 1 instances of WebDriver
Feature: Example feature
As a user of cucumber.js
I want to have documentation on cucumber
So that I can concentrate on building awesome applications
Scenario: Reading documentation # features/homepage.feature:6
Given I am on the Cucumber.js GitHub repository # features/homepage.feature:7
TypeError: this.visit is not a function
at World.<anonymous> (/Users/fraserh/Documents/WorkingDir/protractor/features/homepageSteps.js:14:11)
at doNTCallback0 (node.js:407:9)
at process._tickCallback (node.js:336:13)
When I go to the README file # features/homepage.feature:8
Then I should see "Usage" as the page title # features/homepage.feature:9
(::) failed steps (::)
TypeError: this.visit is not a function
at World.<anonymous> (/Users/fraserh/Documents/WorkingDir/protractor/features/homepageSteps.js:14:11)
at doNTCallback0 (node.js:407:9)
at process._tickCallback (node.js:336:13)
Failing scenarios:
features/homepage.feature:6 # Scenario: Reading documentation
1 scenario (1 failed)
3 steps (1 failed, 2 skipped)
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1
I have the following structure:
conf.js
features/homepage.feature
features/homepageSteps.js
conf.js
exports.config = {
framework: 'cucumber',
seleniumAddress: 'http://192.168.12.100:4724/wd/hub', //this is a working selenium instance
capabilities: {
'browserName': 'chrome'
},
specs: ['features/homepage.feature'],
cucumberOpts: {
require: 'features/homepageSteps.js',
format: 'pretty'
}
};
homepage.feature
Feature: Example feature
As a user of cucumber.js
I want to have documentation on cucumber
So that I can concentrate on building awesome applications
Scenario: Reading documentation
Given I am on the Cucumber.js GitHub repository
When I go to the README file
Then I should see "Usage" as the page title
homepageSteps.js
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
var expect = chai.expect;
module.exports = function() {
var that = this;
this.Given(/^I am on the Cucumber.js GitHub repository$/, function (callback) {
// Express the regexp above with the code you wish you had.
// `this` is set to a new this.World instance.
// i.e. you may use this.browser to execute the step:
this.visit('https://github.com/cucumber/cucumber-js', callback);
// The callback is passed to visit() so that when the job's finished, the next step can
// be executed by Cucumber.
});
this.When(/^I go to the README file$/, function (callback) {
// Express the regexp above with the code you wish you had. Call callback() at the end
// of the step, or callback.pending() if the step is not yet implemented:
callback.pending();
});
this.Then(/^I should see "(.*)" as the page title$/, function (title, callback) {
// matching groups are passed as parameters to the step definition
var pageTitle = this.browser.text('title');
if (title === pageTitle) {
callback();
} else {
callback.fail(new Error("Expected to be on page with title " + title));
}
});
};
It looks like you took the code example from here: https://github.com/cucumber/cucumber-js
And you missed the next piece of code where this.visit function is created:
// features/support/world.js
var zombie = require('zombie');
function World() {
this.browser = new zombie(); // this.browser will be available in step definitions
this.visit = function (url, callback) {
this.browser.visit(url, callback);
};
}
module.exports = function() {
this.World = World;
};
You will need to install zombie package as well:
npm install zombie --save-dev