selenium - CucumberJS tests passing even though it's not possible -
i'm trying convert old ruby tests (which used cucumber, phantomjs , capybara) javascript (using cucumber, phantomjs , selenium) project 100% node based , want remove ruby dependency.
when run tests, pass. problem is, i've not created conditions test pass yet pass impossible. i'm not sure i'm going wrong.
here world.js file:
var {definesupportcode} = require('cucumber'); var seleniumwebdriver = require('selenium-webdriver'), = seleniumwebdriver.by, until = seleniumwebdriver.until; function customworld() { this.driver = new seleniumwebdriver.builder() .withcapabilities(seleniumwebdriver.capabilities.phantomjs()) .build() // returns promise resolves element this.waitforelement = function(locator) { var condition = seleniumwebdriver.until.elementlocated(locator); return this.driver.wait(condition) } } definesupportcode(function({setworldconstructor}) { setworldconstructor(customworld) });
and here step definitions file:
require('dotenv').config(); var chalk = require('chalk'); var {definesupportcode} = require('cucumber'); var seleniumwebdriver = require('selenium-webdriver'), = seleniumwebdriver.by, until = seleniumwebdriver.until; definesupportcode(function({ given, when, }) { given(/^i show environment$/, function (next) { console.log(chalk.green("running against:" + process.env.target_uri)) next() }) when(/^i visit "(.*?)"$/, function (url) { return this.driver.get(url); }) then(/^i should on "([^"]*)"$/, function(page_name) { this.driver.get(process.env.target_uri+'/'+page_name) .then(function() { return this.driver.getcurrenturl(); }) }) then(/^i should see "([^"]*)"$/, function (text) { var xpath = "//*[contains(text(),'" + text + "')]"; var condition = seleniumwebdriver.until.elementlocated({xpath: xpath}); return this.driver.wait(condition, 5000); }); })
the possible tests passing there are: when(/^i visit "(.*?)"$/...
, given(/^i show environment$/...
for reference, here .feature file too:
feature: test global header works expected scenario: header components should exist given visit "/hello" expect see ".c-logo-bar" element , expect see ".c-search-bar" element , expect see ".c-main-nav-bar" element
any ideas i'm going wrong?
Comments
Post a Comment