要定位元素,请使用Target
:
import { Target } from '@serenity-js/protractor';
import { by } from 'protractor';
class CustomerCreatePage {
static customerCode = () =>
Target.the('customer code').located(by.xpath(...));
}
要检索元素的文本,请使用Text
import { Target, Text } from '@serenity-js/protractor';
import { by } from 'protractor';
class CustomerCreatePage {
static customerCode = () =>
Target.the('customer code').located(by.xpath(...));
static customerCodeText = () =>
Text.of(CustomerCreatePage.customerCode())
}
要执行substring
操作,请使用Question.map
:
import { Target, Text } from '@serenity-js/protractor';
import { by } from 'protractor';
class CustomerCreatePage {
static customerCode = () =>
Target.the('customer code').located(by.xpath(...));
static customerCodeText = () =>
Text.of(CustomerCreatePage.customerCode())
.map(actor => value => value.substring(15, 26));
}
要存储该值以便以后可以重用TakeNote
它:
import { actorCalled, TakeNotes, TakeNote, Note } from '@serenity-js/core';
import { BrowseTheWeb } from '@serenity-js/protractor';
import { protractor } from 'protractor';
actorCalled('Sudhir')
.whoCan(
BrowseTheWeb.using(protractor.browser),
TakeNotes.usingAnEmptyNotepad(),
)
.attemptsTo(
TakeNote.of(CustomerCreatePage.customerCodeText).as('customer code'),
// do some other interesting things
Enter.the(Note.of('customer code')).into(someField),
)