如何解决如何从特定的 xpath 获取文本以及如何使用 Serenity 将其存储在字符串中
输入所有输入并提交后,将生成一个新代码,看起来像 Customercode: IN02732114(数字将动态)。
现在我想获取此代码并将其存储在一个字符串中,稍后我想在其他步骤中使用此字符串来使用此代码搜索数据。
我使用以下不同的片段从 xpath 中获取文本。
public static Question customer_code_value() { 返回actor -> Text.of(CustomerCreatePage.CUSTOMER_CODE_TEXT).viewedBy(actor).asstring().substring(15,26); }
字符串代码= customer_code_value(); // 尝试将值存储在字符串代码中
但是 customer_code_value() 方法在 Question 中返回并且不能存储在 String 中。
需要一些关于如何在 Serenity 中获取文本并将其存储在字符串中的帮助。 请帮帮我...
解决方法
要定位元素,请使用 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),)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。