javascript CucumberJS&Selenium的例子

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript CucumberJS&Selenium的例子相关的知识,希望对你有一定的参考价值。

// Declarations for Cucumber
const {Given, When, Then, After} = require('cucumber');
const assert = require('assert').strict;

// Declarations for Selenium
const webdriver = require('selenium-webdriver');
const {By} = require('selenium-webdriver');

// Driver creation for Firefox
let driver;

Given('I am connected to the website', function () {
    driver = new webdriver.Builder().forBrowser('firefox').build();
    return driver.get('http://localhost:1337/index.html');
});

When('I click on the Latest test results link', function () {
    return driver.findElement({id: 'menu_latestTestResult'}).click();
});

When('I click on the Roadmap link', function () {
    return driver.findElement({id: 'menu_roadmap'}).click();
});

Then('the main frame must contain Cucumberjs Report', function () {
    driver.switchTo().frame(0);
    return driver.findElement(By.xpath('/html/body/div[1]/div/div/a')).getText().then(function (foundElement) {
        assert.strictEqual(foundElement, 'Cucumberjs Report');
    });
});

Then('the main frame must contain roadmap.png', function () {
    driver.switchTo().frame(0);
    return driver.findElement(By.xpath('/html/body/img')).getAttribute("src").then(function (foundElement) {
        let isTrue = foundElement.endsWith('roadmap.png');
        assert.strictEqual(isTrue, true);
    });
});

After(function () {
    return driver.close();
});

以上是关于javascript CucumberJS&Selenium的例子的主要内容,如果未能解决你的问题,请参考以下文章

使用CucumberJS / Puppeteer,如何使用多个场景扩展Page对象?

使用Microsoft Edge设置Protractor

javascript中的&&

javascript中用&&跟||来简化if{}else{}的写法

Javascript:解码字符串

html&javaScript&ajax部分