当我在黄瓜中输入演员姓名时,如何使用数据驱动或动态用户名和密码,它应该使用相应的密码,可能来自 json 文件或取决于演员的其他内容。
所以当我在功能文件中输入这个
//example.feature
Feature: Add item and place the order for that item
In order to wear something new
As an online shopping customer
I want to be able to add an item to my shopping bag and then place the order
Scenario: Add an item to shopping bag to place the order using Paypal
Given that "Bruno" is logged in to his "admin" account
When he searches and adds an item from "men" section to his shopping bag
Then he can place the order
// example.steps.ts
import { Actor } from "serenity-js/lib/screenplay";
import { BrowseTheWeb } from "serenity-js/lib/screenplay-protractor";
import { protractor } from "protractor";
import { Start, AddItemsToShoppingBag } from "../website-model/src/index";
import { Authenticate } from '../website-model/src/ability/authenticate';
protractor.browser.ignoreSynchronization = true;
export = function selectItemSteps() {
let actor = Actor.named('Bruno').whoCan(BrowseTheWeb.using(protractor.browser));
this.Given(/^that "([^"]*)" is logged in to his "([^"]*)" account$/, function (name: string, pageUrl: string) {
return actor.attemptsTo(
Start.LaunchUrl(pageUrl, name),
);
});
this.When(/^he searches and adds an item from "([^"]*)" section to his shopping bag$/, function (gender:string) {
return actor.attemptsTo(
AddItemsToShoppingBag.called(gender)
);
});
this.Then(/^he can place the order$/, function () {
return actor.attemptsTo(
// PlaceOrder.hjgkhaksdjh()
);
// expect(james.toSee(thankYouPageElementsMap(lbl_thank_you).Displayed)).eventually.equal('Thank You');
});
}
// 登录用户.ts
import { Task, step, PerformsTasks } from "serenity-js/lib/screenplay";
import { Click, Enter } from "serenity-js/lib/screenplay-protractor";
import { homePageElementsMap } from "../interactions/html-elements/pages-elements-maps/home-page-elements-maps";
import { loginPageElementsMap } from "../interactions/html-elements/pages-elements-maps/login-page-elements-map";
export class LoginUser implements Task {
static called(name: string): LoginUser {
return new LoginUser(name);
}
@step('{0} Login Page - Login Bruno')
performAs(actor: PerformsTasks): PromiseLike<void> {
return actor.attemptsTo(
Click.on(homePageElementsMap.lnk_login),
Enter.theValue('test@test.com').into(loginPageElementsMap.txt_login_email),
Enter.theValue('password111').into(loginPageElementsMap.txt_login_pwd),
Click.on(loginPageElementsMap.btn_login)
);
}
constructor(private name: string) {
}
}