java - 断言为真,变量来自两种方法
问题描述
网址:http ://automationpractice.com/ 登录:testingTest@gmail.com 通过:testtest
我正在尝试自动化购买衣服的过程。
问题是:
我有标签来完成我需要浏览每个标签的过程。地址|添加产品|条款和条件| 付款方式|付款方式| 总结| 我想从“添加的产品”选项卡中获取总价,然后从摘要中获取总价,并通过断言 True 检查它们是否相同。
@FindBy(id = "total_price")
private WebElement totalPriceOfOrder;
@FindBy(id = "total_price")
private WebElement totalPriceOfOrder;
public void checkTotalValueOfOrderInSummaryTab(){
String orderPrice = totalPriceOfOrder.getText();
}
@FindBy(xpath = "/html/body/div/div[2]/div/div[3]/div/div/span")
private WebElement getPriceWhenOrderIsPaid;`
public void getLastPrice(){
String priceIsPaid = getPriceWhenOrderIsPaid.getText();
}
当我尝试断言此方法时,我收到错误,即无法找到 total_price 元素。当然这是不可能的,因为我在检查时位于不同的选项卡上。
那么如何解决呢?如何将价格从第一种方法分配给变量并从第二种方法将其断言为价格?
解决方案
您想要做的是让您的 Get 方法返回该值,以便您的脚本可以存储它并在以后使用它。
例如,更改您的getLastPrice()
方法以返回价格 ( String
)
public String getLastPrice(){
return getPriceWhenOrderIsPaid.getText();
}
然后在您的脚本中,您将存储返回的值以稍后执行断言,例如
String price = getLastPrice();
Assert.areEqual(totalPriceOfOrder.getText(), price, "Verify price");
注意:我不知道您发布的变量是哪个,我只是抓住了几个并以它们为例。
推荐阅读
- css - 如何更改选择组件的边框颜色?
- nuxt.js - 我在添加 Vuetify 时创建 Nuxt 项目的“create-nuxt-app”命令出错,错误如下
- spring - 在 Spring MongoDB Repository 中使用 $slice 和 Kotlin 中的 @Query 时出现注释参数错误
- css - 使用 ASP.net 的 HTML 动作
- c# - 无法使用 EFCore 命令行工具初始化本地 SQL Server 数据库
- java - 处理程序类公共 java.lang.String com.emusicstore.controller.admin.AdminHome.adminPage() 上的映射无效
- tensorflow - 图像序列的分类(固定数量)
- apache-poi - 从 zip 文件中读取多个 xls 文件
- c++ - 从 XML 中读取未指定结构的每个数据成员
- amazon-dynamodb - 在 DynamoDB 中插入地图