Protractor tests are passing but didn't execute the tests - protractor

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.

Related

browser is not catching given url when i am running the step definition file in protractor-cucumber

I am new to this protractor-cucumber.please correct me if i am going wrong.
i am using protractor 3.2.2
when i am run feature file, it gives correct output.but when i am run step definition, the browser not taking the given url.
My feature file is given below.
Feature: Login page test
Scenario: Verify whether the user is able to view the login page while
giving the URL.
Given I go to "http://localhost:4200/login"
When The URL of the page should be "http://localhost:4200/login"
My step definition file is given below.
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 {string}', function (string) {
browser.get(string);
});
this.When('The URL of the page should be {string}', function (string) {
expect(browser.getCurrentUrl()).to.eventually.equal(string);
});
}
My config. file is given below
exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
allScriptsTimeout: 11000,
specs: [
'features/*.feature'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:4200/login',
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
cucumberOpts: {
require: 'features/step_definitions/*.js',
tags: false,
format: 'pretty',
profile: false,
'no-source': true
} };
The error showing when i am run 'protractor protractor.conf.js' is given below.
Using ChromeDriver directly...
[launcher] Running 1 instances of WebDriver
(node:7508) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use
os.tmpdir() instead.
[7884:6800:1229/145724.847:ERROR:browser_gpu_channel_host_factory.cc(107)]
Failed to launch GPU process.
DevTools listening on ws://127.0.0.1:12425/devtools/browser/74f2a81c-51c2-
4a8a-afec-26166a388d1f
C:\Users\CS1027C\AppData\Roaming\npm\node_modules\protractor\node_modules\se
lenium-webdriver\http\index.js:365
onError(new Error(message));
^
Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:54206
at ClientRequest.<anonymous> (C:\Users\CS1027C\AppData\Roaming\npm\node_modu
les\protractor\node_modules\selenium-webdriver\http\index.js:365:15)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at Socket.socketErrorListener (_http_client.js:387:9)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
From: Task: WebDriver.createSession()
at acquireSession (C:\Users\CS1027C\AppData\Roaming\npm\node_modules\protrac
tor\node_modules\selenium-webdriver\lib\webdriver.js:62:22)
at Function.createSession (C:\Users\CS1027C\AppData\Roaming\npm\node_modules
\protractor\node_modules\selenium-webdriver\lib\webdriver.js:295:12)
at new Driver (C:\Users\CS1027C\AppData\Roaming\npm\node_modules\protractor\
node_modules\selenium-webdriver\chrome.js:778:38)
at DirectDriverProvider.getNewDriver (C:\Users\CS1027C\AppData\Roaming\npm\n
ode_modules\protractor\built\driverProviders\direct.js:69:16)
at Runner.createBrowser (C:\Users\CS1027C\AppData\Roaming\npm\node_modules\p
rotractor\built\runner.js:203:37)
at C:\Users\CS1027C\AppData\Roaming\npm\node_modules\protractor\built\runner
.js:293:21
at _fulfilled (C:\Users\CS1027C\AppData\Roaming\npm\node_modules\protractor\
node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\Users\CS1027C\AppData\Roaming\npm\node_modu
les\protractor\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\Users\CS1027C\AppData\Roaming\npm\nod
e_modules\protractor\node_modules\q\q.js:796:13)
at C:\Users\CS1027C\AppData\Roaming\npm\node_modules\protractor\node_modules
\q\q.js:556:49
[launcher] Process exited with error code 1
From the error message:
Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:54206,
your issue should caused by using lower chromedriver with higher Chrome browser, upgrade the chromedriver should fix your problem.
And change the cucumberOpts in your config file as below:
cucumberOpts: {
monochrome: true,
strict: true,
plugin: ["pretty"],
require: [
'features/step_definitions/*.js'
],
tags: ''
}
Change your step defintion file as below: (if you use Cucumber 1 or below)
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 (url) {
browser.get(url);
});
this.When('The URL of the page should be "(.*?)"', function (url) {
expect(browser.getCurrentUrl()).to.eventually.equal(url);
});
};
Change your step defition file as below (if you use Cucumber 2 or above)
var {defineSupportCode} = require('cucumber');
defineSupportCode(function ({ Given, When, Then }) {
Given('I go to "(.*?)"', function (url) {
browser.get(url);
});
When('The URL of the page should be "(.*?)"', function (url) {
expect(browser.getCurrentUrl()).to.eventually.equal(url);
});
});

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 config file is not picking up the cucumber step definitions

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 .

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.

Testing async with karma

I am trying to set up some async tests using karma and jasmine. I am clearly making a very stupid mistake but I need it pointing out to me. After simplifying as much as possible I have the following:
package.json
{
"name": "newtest",
"version": "0.0.0",
"scripts": {
"test": "karma start karma.conf.js"
},
"devDependencies": {
"karma": "^0.12.28",
"karma-chrome-launcher": "^0.1.5",
"karma-jasmine": "^0.2"
}
}
karma.conf.js
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'tests/**/*.js'
],
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['Chrome'],
singleRun: true
});
};
tests/dummy.spec.js
describe("Testing async", function() {
it('should fail this test', function(done) {
setTimeout(function(){
expect(1).toBe(2);
done();
}, 1000);
});
it('should not fail this test', function(done) {
done();
});
});
and I am getting the following:
npm test
> newtest#0.0.0 test /home/mark/Projects/newtest
> karma start karma.conf.js
INFO [karma]: Karma v0.12.16 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 39.0.2171 (Linux)]: Connected on socket T7j6LvNAwvS89wUdymCb with id 16891024
Chrome 39.0.2171 (Linux) Testing async should not fail this test FAILED
TypeError: undefined is not a function
at null.<anonymous> (/home/mark/Projects/newtest/tests/dummy.spec.js:12:5)
Chrome 39.0.2171 (Linux): Executed 2 of 2 (1 FAILED) (0.007 secs / 0.005 secs)
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
So the test that I think should fail is passing fine, and vice-versa. Can someone point me to my error(s)?
I guess the first one fail because when the timeout is reach the test is allready finish, so both doesn't work.
It's has you'r not using jasmine 2.
The syntax seems good to me, what I can tell you is the difference with my configuration (wich is working) :
I have put karma-jasmine in dependencies with a ~ :
"dependencies": {
...
"karma-jasmine": "~0.2.0"
},
I'm using PhantomJS :
browsers:['PhantomJS'],
I don't know why I am having the problem, but I have tried on another machine and it works as expected.