本文整理匯總了TypeScript中cucumber.When函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript When函數的具體用法?TypeScript When怎麽用?TypeScript When使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了When函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: require
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const expect = chai.expect;
chai.use(chaiAsPromised);
let homePage = new HomePage();
// supports/timeout.js
const { setDefaultTimeout } = require("cucumber");
let title;
let input;
let button;
setDefaultTimeout(60 * 1000);
Given(/^I Navigate to google.com$/, () => {
browser.get("https://www.google.com/");
});
When(/^I enter something in the search bar$/, () => {
input = element(by.xpath("//input[@title = 'Search']"));
input.sendKeys('HELLO').then(() => {
console.log('Value' + input.value);
expect(input.value).to.equal('HELLO');
});
button = element(by.xpath("//input[@aria-label='Google Search']"));
button.click();
});
示例2: FormPage
// import { setWorldConstructor } from 'Cucumber';
import { expect } from 'chai';
import { Given, When, Then } from 'cucumber';
import { FormPage } from '../pages/form.po';
import { browser } from '../../node_modules/protractor';
const page = new FormPage();
Given('I am on the form', () => page.navigateTo());
When('I set my team {string}', (team) => {
page.setTeam(team);
});
When('I set my activity {string}', (activity) => {
page.setActivity(activity);
});
When('I set my start date {string}', (startDate) => {
page.setStartDate(startDate);
});
When('I set my end date {string}', (endDate) => {
page.setStartDate(endDate);
});
When('I set my status {word}', (status) => {
page.setStatus(status);
});
When('I click on save button', () => {
示例3: Calculator
import { Calculator } from "../PageObjects/Calculator";
import { AngularHome } from "../PageObjects/AngularHome";
let calc = new Calculator();
let angularPage = new AngularHome();
Given('I navigate to {string} Site', async (siteUrl) => {
await browser.manage().window().maximize();
await browser.get(siteUrl);
});
When('I add two numbers {string} and {string}', async (num1, num2) => {
await calc.firstTextBox.sendKeys(num1);
await calc.secondTextBox.sendKeys(num2);
});
Then('output displayed is {string}', async (text) => {
await calc.goButton.click();
await calc.result.getText().then(function (repeaterText) {
console.log("The output of Calculator addition is -> " + repeaterText);
});
});
When('I click on header link', async () => {
開發者ID:ashutoshchittora,項目名稱:TypeScriptCucumberProtractorVisualStudioCode,代碼行數:30,代碼來源:demoStepDefinition.ts
示例4: StepSampleWithoutDefineSupportCode
function StepSampleWithoutDefineSupportCode() {
setWorldConstructor(function({attach, parameters}) {
this.attach = attach;
this.parameters = parameters;
this.visit = (url: string, callback: Callback) => {
callback(null, 'pending');
};
this.toInt = parseInt;
});
Before((scenarioResult: HookScenarioResult, callback: Callback) => {
console.log(scenarioResult.result.status === Status.FAILED);
callback();
});
Before({ timeout: 1000 }, (scenarioResult: HookScenarioResult, callback: Callback) => {
console.log(scenarioResult.result.status === Status.FAILED);
callback();
});
Before('@tag', (scenarioResult: HookScenarioResult, callback: Callback) => {
console.log(scenarioResult.result.status === Status.FAILED);
callback();
});
BeforeAll((callback: Callback) => {
console.log("Before all");
callback();
});
BeforeAll({ timeout: 1000 }, (callback: Callback) => {
console.log("Before all");
callback();
});
BeforeAll('@tag', (callback: Callback) => {
console.log("Before all");
callback();
});
After((scenarioResult: HookScenarioResult, callback: Callback) => {
console.log("After");
callback();
});
After({ timeout: 1000 }, (scenarioResult: HookScenarioResult, callback: Callback) => {
console.log("After");
callback();
});
After('@tag', (scenarioResult: HookScenarioResult, callback: Callback) => {
console.log("After");
callback();
});
AfterAll((callback: Callback) => {
console.log("After all");
callback();
});
AfterAll({ timeout: 1000 }, (callback: Callback) => {
console.log("After all");
callback();
});
AfterAll('@tag', (callback: Callback) => {
console.log("After all");
callback();
});
Given(/^a variable set to (\d+)$/, (x: string) => {
console.log("the number is: " + x);
});
Given(/^a variable set to (\d+)$/, (x: number) => {
console.log(typeof x);
});
Given(/^I am on the Cucumber.js GitHub repository$/, function(callback: Callback) {
this.visit('https://github.com/cucumber/cucumber-js', callback);
});
When(/^I go to the README file$/, (title: string, callback: Callback) => {
callback(null, 'pending');
});
Then(/^I should see "(.*)" as the page title$/, {timeout: 60 * 1000}, function(title: string, callback: Callback) {
const pageTitle = this.browser.text('title');
if (title === pageTitle) {
callback();
} else {
callback(new Error("Expected to be on page with title " + title));
}
});
// Type for data_table.js on
// https://github.com/cucumber/cucumber-js/blob/a5fd8251918c278ab2e389226d165cedb44df14a/lib/cucumber/ast/data_table.js
Given(/^a table step with Table raw$/, (table: Table) => {
//.........這裏部分代碼省略.........
示例5: When
import { When } from 'cucumber'
import fs from 'fs-extra'
import path from 'path'
When(
/^(trying to execute|executing) the "([^"]+)" example$/,
{ timeout: 100000 },
async function(tryingText, exampleName) {
const expectError = determineExpectError(tryingText)
await fs.copy(
path.join('documentation', 'examples', exampleName),
this.rootDir
)
await this.execute({ command: 'run', expectError })
finish(
expectError,
this.process && (this.process.error || this.process.exitCode)
)
}
)
When(/^(trying to run|running) "([^"]*)"$/, async function(
tryingText,
command
) {
const expectError = determineExpectError(tryingText)
await this.execute({ command, cwd: this.rootDir, expectError })
finish(expectError, this.process.error || this.process.exitCode)
})
When(/^(trying to run|running) text-run$/, async function(tryingText) {
示例6: setDefaultTimeout
setDefaultTimeout(60 * 1000);
Given(/^I nagivate to the application$/, () => {
homePage.getHomePage();
});
When(/^I land on the home page$/, () => {
let title;
homePage.getTitle()
.then(data => {
title = data;
expect(title).to.equal('AT&T Community Forums');
console.log(`TITLE: ${data}`);
})
.catch(err => {
console.log(`The error was ${err}`);
});
input = homePage.getSearchInput();
input.sendKeys('asdfasdfasdflkjal;kejf;alskdfj');
});
Then(/^I expect homePage title to be correct$/, () => {
// console.log(input.getSearchInput());
console.log(input.value);
});
示例7: Given
this.appendFile({
path: path.join('src', barrel, 'index.js'),
contents: `export * from './${file}';`
})
]);
});
Given('I have a project', { timeout: -1 }, async function() {
await this.createProject();
});
/**
* When I Do
*/
When('I run beaver with {string}', function(command: string) {
this.run(command);
});
When('I respond to the prompts with:', async function(
questions: TableDefinition
) {
await this.respondTo(questions.hashes() as Question[]);
});
When(
'I wait for the command to finish with code {int}',
{ timeout: -1 },
async function(code) {
await this.ended();
expect(this.output.code).to.equal(
示例8: require
import { browser, protractor } from "protractor";
import { SearchPageObject } from "../pages/searchPage";
const { When, Then } = require("cucumber");
const search: SearchPageObject = new SearchPageObject();
When(/^I type "(.*?)"$/, async (text) => {
await search.searchTextBox.sendKeys(text);
});
Then(/^I click on search button$/, async () => {
await browser.actions().sendKeys(protractor.Key.ENTER).perform();
});