john-doherty / selenium-cucumber-js Goto Github PK
View Code? Open in Web Editor NEWBrowser automation framework written in pure JavaScript using official selenium-webdriver and cucumber-js
License: ISC License
Browser automation framework written in pure JavaScript using official selenium-webdriver and cucumber-js
License: ISC License
Hello friends,
anybody knows how to detect on the hook AfterScenario if it failed or no?
I tried already with: IsFailed
if (!scenario.isFailed) { driver.call(setScore, null, 'pass').then(function(result){ console.log('set score to pass'); }); } done();
I had no cluck with that.
Any idea is always welcome.
I want to convert selenium feature file into a script file, so I can directly execute that script. How can I do that?
I really only want the command line summary. I don't want the report opening automatically in my browser on each run.
Hi,
Thanks again for the shell.
The problem I've run into a couple times is that the two NPM packages you have in a local node_modules are of different (older) versions than what I'm using, which results in mis-matched objects.
Everything works fine if I delete your package-local node_modules.
After npm install I got
node ./node_modules/selenium-cucumber-js/index.js
module.js:472
throw err;
^
Error: Cannot find module 'eyes.selenium'
I installed eyes.selenium using
npm install eyes.selenium --save
Weirdly it eyes.selenium is listed as a dependency in this project.
Edited:
Oh it's listed in dev dependencies
I have a two features and if i do run
node ./node_modules/selenium-cucumber-js/index.js
I get
node_modules/selenium-cucumber-js/runtime/world.js:177 The previously configured ChromeDriver service is still running. You must shut it down before you may adjust its configuration.
Expected
One test ends another start
Hello. How can I change global language for features?
In cucumber-js
I can use cli options --language
but in selenium-cucumber-js
I use # language: ru
at first line of feature for every feature
1 - how to use es6.
2 - To cucumber-html-reporter - how to setup metadata
3 - how to customize report
It is really a awesome project
so thank you
By any Chance Can I execute multiple Features/Scenarios in parallel.
Also is there any way i can execute same feature or scenario on different browsers at once - same time.
When I run tests using Phantomjs - ajax is pending.
such settings
'phantomjs.cli.args': ['--web-security=false', '--ignore-ssl-errors=true', '--webdriver-loglevel=DEBUG'],
could help to resolve this issue
Hi,
The chromedriver you have in your node_modules is .25 which does not support async/await.
The most recent version is .30.
-Lee
I'd like to integrate Mink into this project ala https://github.com/Adezandee/cucumber-mink, are there plans afoot to do this already?
Hello friends,
I'm experiencing an issue when the tests finished to run successfully or no. When it is trying to generate the HTML report, I get this message:
`/Users/demo/test/Projects/demo/demo.Automated.JS.Tests/node_modules/selenium-cucumber-js/node_modules/cucumber/lib/cucumber/runtime/event_broadcaster.js:30
process.nextTick(function(){ throw error; }); // prevent swallow by unhandled rejection
^
TypeError: node_modules/selenium-cucumber-js/runtime/world.js:191 Cannot read property 'trim' of undefined
at sanitize (/Users/demo/test/Projects/demo/demo.Automated.JS.Tests/node_modules/selenium-cucumber-js/node_modules/cucumber-html-reporter/lib/reporter.js:27:21)
at generateReport (/Users/demo/test/Projects/demo/demo.Automated.JS.Tests/node_modules/selenium-cucumber-js/node_modules/cucumber-html-reporter/lib/reporter.js:52:24)
at Object.generate (/Users/demo/test/Projects/demo/demo.Automated.JS.Tests/node_modules/selenium-cucumber-js/node_modules/cucumber-html-reporter/lib/reporter.js:419:9)
at Object.generateReport [as generate] (/Users/demo/test/Projects/demo/demo.Automated.JS.Tests/node_modules/selenium-cucumber-js/node_modules/cucumber-html-reporter/index.js:30:21)
at /Users/demo/test/Projects/demo/demo.Automated.JS.Tests/node_modules/selenium-cucumber-js/runtime/world.js:207:22
at process._tickCallback (internal/process/next_tick.js:150:11)`
Do you know what library or setup is missing?
Once again, I would like to say THANK YOU for this amazing library.
Looking to use the "attach" to include a screenshot of a particular step. This is outlined in cucumber-js as seen by this code:
Given(/^a basic step$/, function() {
this.attach('Some info.')
this.attach('{"some", "JSON"}}', 'application/json')
})
from:
https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/attachments.md
error is:
this.attach is not a function
At first I thought it was because I was using an arrow function (per the cucumber notes this doesn't work because of rebinding), but I switched to a regular function and still no luck.
Thanks!
Jus a question and not a bug per se, but, are there any plans to support Cucumber.js 2.x?
Hi,
I've not been able to get the Before/After Feature or Scenario event handlers working in my step definitions.
this.BeforeFeature(/^Feature Name$/, function () {
return helpers.loadPage('http://localhost/login').then(function() {
return page.login.login(shared.testData.username, shared.testData.password);
});
});
Is there an example of how to do this? The above code works in a When - is something like this possible in a Before/After?
Thanks!
Running my test suite from the command-line, I specify "-x 20000", but since version 1.4.9 I've seen this error:
function timed out after 10000 milliseconds
I'm sure it had worked prior.
Adding selenium-cucumber-js
to a project is a bit of a hassle as you have to create the dependant folders. It would be far cleaner to execute two commands and have the framework up and running. For example
# install the framework
npm install --save-dev selenium-cucumber-js
# create folders and insert google example
node ./node_modules/selenium-cucumber-js/index init
I have read the readme file, but I do not understand where those should be located.
lets take an example, I want to print the name of the feature before each feature.
// before-hook.js
module.exports = function () {
// add a before feature hook
this.BeforeFeature(function(feature, done) {
console.log('BeforeFeature: ' + feature.getName());
done();
});
};
Thanks!
We use our test suite as a health-checking framework ("are services a, b, and c online?") which runs every 3 minutes.
While the json report output is useful for us (jenkins integration via the Cucumber Test Result Plugin), neither the junit nor the html reports will ever been looked at.
While this sounds innocuous, the html report generator will write out the screenshots to disk on every failure. These screenshots will never be cleaned up between test suite runs resulting in a bunch of stray files over time.
My work around is to simply delete the screenshots directory as an extra step in our jenkins job, but it would be nice if we could disable the output completely.
Thanks again for this great framework.
As in this part of the code world.js:100 the page objects are created before the shared object, therefore if a shared property / method is needed inside of a page object n definition time the system crashes with a not defined error.
Is there is any specific reason why this is done in this way?
I think has more sense to do it in the other way around. Think in the scenario where you would like to create some abstract shared object.
In my case I was trying to augment the object by adding a customised locator, I defined in a utils shared object and when trying to use my customised locator in a page object as defined in the how to, it fails due the page object get created before shared objects.
Hi,
I tried to run this project with just updating cucumber version to latest(4.2.1).
But I've caught an error below:
My-MAC:selenium-cucumber-js fbb$node index.js
/Users/fbb/Frameworks/cucumber-test8/selenium-cucumber-js/node_modules/babel-runtime/helpers/classCallCheck.js:7
throw new TypeError("Cannot call a class as a function");
^
TypeError: Cannot call a class as a function
at exports.default (/Users/fbb/Frameworks/cucumber-test8/selenium-cucumber-js/node_modules/babel-runtime/helpers/classCallCheck.js:7:11)
at Object.Cli (/Users/fbb/Frameworks/cucumber-test8/selenium-cucumber-js/node_modules/cucumber/lib/cli/index.js:78:34)
at Object. (/Users/fbb/Frameworks/cucumber-test8/selenium-cucumber-js/index.js:128:28)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
at startup (internal/bootstrap/node.js:238:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
Kindly let me know what am I doing wrong here.
I am unable to trigger the scripts on Microsoft EDGE.
Added following settings in world.js
case 'edge': {
console.log('in world edge');
driver = new selenium.Builder().withCapabilities({
browserName: 'microsoftedge',
javascriptEnabled: true,
acceptSslCerts: true,
path: "path to microsoftWebdriver.exe"
}).build();
} break;
getting error : do not know to initiate microsoftedge.
Hi,
I am new with selenium-cucumber-js, I would like to add custom message and screenshot to the html report, but I dont know how.
I am not sure if the FW also support this, if not please consider to support this. Otherwise, appreciate if you can give me an example.
I install without errors and run a simple test, I get this error:
1) Scenario: Google search for nothing specific - features/google-search.feature:6
Step: When I search Google for "nothing specific" - features/google-search.feature:7
Step Definition: step-definitions/google-search-steps.js:3
Message:
Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:61285
at ClientRequest.<anonymous> (/Users/me/some-project/node_modules/selenium-webdriver/http/index.js:238:15)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:189:7)
at Socket.socketErrorListener (_http_client.js:358:9)
at emitOne (events.js:96:13)
at Socket.emit (events.js:189:7)
at emitErrorNT (net.js:1280:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
From: Task: WebDriver.createSession()
at Function.createSession (/Users/me/some-project/node_modules/selenium-webdriver/lib/webdriver.js:777:24)
at Function.createSession (/Users/me/some-project/node_modules/selenium-webdriver/chrome.js:709:29)
at createDriver (/Users/me/some-project/node_modules/selenium-webdriver/index.js:167:33)
at Builder.build (/Users/me/some-project/node_modules/selenium-webdriver/index.js:639:16)
at getDriverInstance (/Users/me/some-project/node_modules/selenium-cucumber-js/runtime/world.js:62:16)
at /Users/me/some-project/node_modules/selenium-cucumber-js/runtime/world.js:149:29
I am on latest stable macOS and Chrome 57 (also did not work with 56 though).
Any idea where to look at to fix this?
Hello. I'm having some problem with executing scripts.
Here's a code sample
getDocumentLoadStatus: function () {
let status = driver.executeScript("document.readyState");
console.log(status);
}
I expect "complete" result, but getting such in console:
ManagedPromise {
flow_:
ControlFlow {
propagateUnhandledRejections_: true,
activeQueue_:
TaskQueue {
name_: 'TaskQueue::3',
flow_: [Circular],
tasks_: [Array],
interrupts_: null,
pending_: null,
subQ_: null,
state_: 'new',
unhandledRejections_: Set {} },
taskQueues_: Set { [Object] },
shutdownTask_: null,
hold_:
Timeout {
_called: false,
_idleTimeout: 2147483647,
_idlePrev: [Object],
idleNext: [Object],
idleStart: 437,
onTimeout: [Function],
timerArgs: undefined,
repeat: 2147483647,
destroyed: false,
[Symbol(asyncId)]: 35,
[Symbol(triggerAsyncId)]: 26 } },
stack: { Task: WebDriver.executeScript()
at thenableWebDriverProxy.schedule (/Users/azadykhin/Code/Wallet/node_modules/selenium-webdriver/lib/webdriver.js:815:17)
at thenableWebDriverProxy.executeScript (/Users/azadykhin/Code/Wallet/node_modules/selenium-webdriver/lib/webdriver.js:886:16)
at Object.waitForDocumentLoad (/Users/azadykhin/Code/Wallet/features/page_objects/dialogue-start-disclaimer.js:17:29)
at createWorld. (/Users/azadykhin/Code/Wallet/features/step_definitions/start.js:53:38)
at combinedTickCallback (internal/process/next_tick.js:131:7) name: 'Task' },
parent: null,
callbacks: null,
state: 'pending',
handled: false,
value: undefined,
queue: null }
Could you please tell me what I'm doing wrong? Thanks
Hi!
I try use driver
in this.AfterScenario
but I catch this error:
NoSuchSessionError: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.
In this.AfterScenario
I can't use driver
instance?
Hi,
Love the wrapper. Thank you for it.
What I need is to be able to control the driver configuration (browsers, resolutions, and local, versus remote).
Do you have or plan to have a hook or configuration option for driver construction?
-Lee
I'd like to only start a fresh browser session after each feature.
Hi,
Is there anyway that we can improve this framework to execute the scenarios in parallel?
I have Windows 7 and after I cloned application and run npm install and then node index.js I got following error
selenium-cucumber-js\node_modules\selenium-web
driver\index.js:115
static createSession(...args) {}
^^^
SyntaxError: Unexpected token ...
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:414:25)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object. (C:\Users\Vera\Desktop\SlotMachine\selenium-cucumber-j
s\runtime\world.js:13:16)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
I want to assert a heading's text on a webpage.
I want to assert "Hi" from the heading.
I tried like this:
this.Then(/^I should see Hi$/m, function(){
driver.wait(until.elementsLocated(by.css('#body-section > div > div.row > div')), 10000);
return driver.findElement(by.css('h3.RTL')).then(function(e){
expect(e.getText()).to.include('Hi');
})
});
Please help...
gettting
TypeError: Cannot read property 'url' of undefined at createWorld.<anonymous> (/Users/rhowk1271/Sites/time/_style/instyle/be-fe-instyle/features/step_definitions/buy-workwear-steps.js:6:53) at _combinedTickCallback (internal/process/next_tick.js:95:7) at process._tickCallback (internal/process/next_tick.js:161:9) at Function.Module.runMain (module.js:607:11) at startup (bootstrap_node.js:158:16)
when I run the example using the directory structure cited at the end of the readme, and the command:
node ./node_modules/selenium-cucumber-js/index.js -s ./features/step_definitions -p ./features/page_objects -o ./features/shared_objects -r ./features/reports
Thanks in advance for any help!
Whole error
Downloading https://chromedriver.storage.googleapis.com/2.28/chromedriver_win32.zip
Saving to C:\GITWOR1\VIMTHI1\AppData\Local\Temp\chromedriver\chromedriver_win32.zip
Receiving...
ChromeDriver installation failed Error with http request: { 'cache-control': 'no-cache',
pragma: 'no-cache',
'content-type': 'text/html; charset=utf-8',
'proxy-connection': 'close',
connection: 'close',
'content-length': '756' }
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node install.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
how to deal with it ?
Hello @john-doherty! I try to use "stalenessOf( element )" condition
driver.wait(until.stalenessOf('mat-spinner'));
but I got "TypeError: element.getTagName is not a function"
How can I wait until element will be invisible?
Hello friends,
I'm trying to load a page and perform a login action under a Hook before run the actual feature so I can login multiple users from the Hook based on Tags. Since multiple backgrounds are not allowed on features by cucumber, I was thinking on this solution.
when trying to implement it, I'm trying to load a url using the helper or directly using driver.get ,however, it fires an error:
TypeError: node_modules/selenium-cucumber-js/node_modules/cucumber/lib/cucumber/support_code/library.js:17 Cannot read property 'get' of null
Anybody has any idea about how to fix this?
My Hook code is:
/* * Adds a before feature hook */ this.BeforeFeature(function(feature, done) { feature.getTags().forEach(function (tag) { // Only features for Client Access if(tag.getName() === '@user-01') { // load the url and wait for it to complete driver.get("https://google.com/").then(function() { // now wait for the body element to be present return driver.wait(until.elementLocated(by.css('body')), 10000); }); } }); done(); });
We're doing some experimenting with headless chrome in place of phantomjs for our testing.
It seems headless chrome needs a pretty recent version of chromedriver. This package currently only gets chromedriver 2.28, and the "getting started with headless chrome" page recommends at least version 2.32 (latest: 2.33)
Any chance for an update?
What about removing whitespaces from both sides of strings in the condition of 'getElementsContainingText' helper ?
By changing it with something like this:
if (elements[i][txtProp].trim() === content.trim()) {
results.push(elements[i]);
}
The problem I encounter is that HTML tags had not the same innerText and textContent string values and both could contained (not the same) leading and trailing whitespace(s) and carriage return(s).
So, If I want to search "Hello" in these examples, currently only the first will work all the time:
<span>Hello</span>
<span> Hello </span>
<span>
Hello
</span>
As a workaround, I copy-paste the getElementsContainingText content function in my test code with the fix above.
Hi ,
I really like the repo but I want to follow the standard cucumber structure and run from IDE ( from Webstorm).
i followed the steps you mentioned in the intelliJ cucumber plugin section, and I am able to run the repo with command
node ./index.js -s ./features/step_definitions -p ./features/page_objects -o ./features/shared_objects -r ./features/reports
but then when I run the repo using just cucumberjs command, i get various errors. for example it says 'by is not defined'.
can you let me know how to structure the framework so that I can run from command line by just giving cucumberjs or in the intelliJ, right click on the scenario and run the scenario.
I have attached snapshots , how I would like to run. The reason I want to run like this is, its easier to debug and run in one go everything from the editor.. Appreciate your help.
The actual command the editor runs is
./node_modules/.bin/cucumberjs /Users/raja/projects/JavaScript_frameworks/selenium-cucumber-js/features/google-search.feature --format summary --require /Users/raja/projects/JavaScript_frameworks/selenium-cucumber-js/features --require /Applications/WebStorm.app/Contents/plugins/CucumberJavaScript/lib/cucumberjs_formatter_nix.js
(copy pasted from editor)
ideally if i can run with cucumberjs command, then I should be able to figure out how to run in editor.
many thanks.
When code checked out and installed the reports is missing so testrun fails
https://yarnpkg.com/en/docs/cli/install
At the moment, the only way to be able to use this package via yarn is to add "--ignore-engines"
Currently to run my automation tests i am using *node index.js -s .\step-definitions -r .\reports*
to run a specific feature i need to add a tag and then use it in above command with a -t arg
but i have existing set of feature files where I donot have proper tags, is there some way we can specify a single .feature file in the above command to execute the tests as we can do with cucumber-js
eg : providing : .\features\login.feature
Hi,
I'm using a selenium-cucumber-js.json file at the root of my project with these options:
{
"steps": "./features/step-definitions",
"pageObjects": "./page-objects",
"sharedObjects": "./shared-objects",
"reports": "./reports",
"browser": "firefox",
"timeout": 100000
}
but when I run the tests (>node ./node_modules/selenium-cucumber-js/index.js), the options used are the ones on index file:
{
"steps": "./step-definitions",
"pageObjects": "./page-objects",
"sharedObjects": "./shared-objects",
"reports": "./reports",
"browser": "chrome",
"timeout": 10000
}
Am I doing anything wrong? Or there is a problem on index.js when reading the file?
var configFileName = path.resolve(process.cwd(), 'selenium-cucumber-js.json');
if (fs.isFileSync(configFileName)) {
config = Object.assign(config, require(configFileName));
}
Thanks,
Vitor Carvalho
How do I set custom web driver instances ? Do I need a configuration file where I can add desired capabilites and browser configurations . At the moment it's not clear how this is done . Is there an example ?
For consistency, the config properties from the newly created selenium-cucumber-js.json
file should match those in the README.
Apologies for being a pest, BUT, for our jenkins test runner, it's very helpful to use the --no-colors option with cucumber otherwise we get a bunch of escape codes like [32mโ Then the tag "title" should be visible[39m
in our output.
So I was wondering if there was a generic mechanism to pass options to cucumber, or do you have to mirror specific options to be passed through?
Thanks once more.
I've installed the latest version (1.5.1) with the "eyes" integration -- which i don't actually use.
When i get a failure in my tests, i now also get the following:
Error: Promise factory was not initialized with proper callback
at PromiseFactory.makePromise (/var/lib/jenkins/workspace/unb-lib-tests/node_modules/eyes.utils/src/PromiseFactory.js:49:15)
at EyesBase.abortIfNotClosed (/var/lib/jenkins/workspace/unb-lib-tests/node_modules/eyes.sdk/src/EyesBase.js:968:32)
at /var/lib/jenkins/workspace/unb-lib-tests/node_modules/selenium-cucumber-js/runtime/world.js:229:33
at ManagedPromise.invokeCallback_ (/var/lib/jenkins/workspace/unb-lib-tests/node_modules/selenium-webdriver/lib/promise.js:1341:14)
at TaskQueue.execute_ (/var/lib/jenkins/workspace/unb-lib-tests/node_modules/selenium-webdriver/lib/promise.js:2950:14)
at TaskQueue.executeNext_ (/var/lib/jenkins/workspace/unb-lib-tests/node_modules/selenium-webdriver/lib/promise.js:2933:27)
at asyncRun (/var/lib/jenkins/workspace/unb-lib-tests/node_modules/selenium-webdriver/lib/promise.js:2793:27)
at /var/lib/jenkins/workspace/unb-lib-tests/node_modules/selenium-webdriver/lib/promise.js:675:7
at process._tickCallback (internal/process/next_tick.js:109:7)
Hi another possible bug on world.js:76 as per Cucumber documentation
World is an isolated context for each scenario
Therefore no "world" would have been created at the moment of execute the first BeforeFeature hook.
My recommendation would be to create the common global objects at the begging (A pull request will be sent)
Hi John, this isnt an issue, just wanted to get some help around tweaking this framework to support appium, if you have ever tried launching tests to appium from the world.js or any other way.
Would be great to get few thoughts from you around it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.