appium - isEnabled 属性在 Appium 中未按预期工作
问题描述
有人可以用外行的方式向我解释命令 isEnabled() 在 Appium 场景中的工作原理:特定移动页面上有 3 个复选框。- Checkbox 1, Checkbox2 & Checkbox3 “Checkbox3”默认是禁用的,只有当我们选择“Checkbox2”时才会启用</p>
TC是验证“Checkbox3”是否默认禁用,并打印如下输出“Checkbox3 is current Disabled”</p>
启用“Checkbox3”后,我们需要打印以下输出“Checkbox3 is current Enabled”</p>
我将其作为 TestNG 执行并使用以下代码行
boolean FirstValue = XMLPage.ListofCheckboxes.get(2).isEnabled();
System.out.println(FirstValue);
if(FirstValue=false)
{
System.out.println("Checkbox3 is currently Disabled");
}
else
{
System.out.println("Checkbox3 is currently Enabled");
}
Thread.sleep(4000);
XMLPage.ListofCheckboxes.get(1).click();
boolean SecondValue = XMLPage.ListofCheckboxes.get(2).isEnabled();
System.out.println(SecondValue);
if(SecondValue=true)
{
System.out.println("Checkbox3 is currently Enabled");
}
else
{
System.out.println("Checkbox3 is currently Disabled");
}
预期输出:
- 错误的
- “复选框 3 当前已禁用”
- 真的
- “复选框 3 当前已启用”
实际输出:
- 错误的
- “复选框 3 当前已启用”
- 真的
- “复选框 3 当前已启用”
它第一次遇到 if 语句时不应该将输出打印为“Checkbox3 当前已禁用”我不确定为什么它会打印“else”下提到的输出{即:-“Checkbox3 当前已启用”}。如输出所示,命令“boolean FirstValue = XMLPage.ListofCheckboxes.get(2).isEnabled();”返回的值 是假的,因此代码应该打印“if”而不是“else”下提到的输出。
解决方案
您在代码中使用的 if 语句是错误的。
代码中的 if 语句
if(FirstValue=false){
....
}
这是一个赋值操作,因为您使用单个=符号。它将做的是,它将 FirstValue 分配为 false,然后由于 if 块内的值现在为 false,它会转到 else 块。这是一个有效的操作,因此可以正常编译。但是 if 语句应该是一个比较步骤,如下所示,使用==符号,
if 语句应该是一个比较步骤,
if(FirstValue==false){
....
}
这就是你输出错误的原因。
推荐阅读
- ios - 尝试在登机时运行时应用程序委托出错
- python-3.x - 图像、pdf 附件到 couchbase 并读取 blob 文件类型并从 couchbase 重新生成文件
- spring-boot - Spring Boot 2 测试:我怎样才能只有一个 EntityManager?
- javascript - 在反应中将数组数据转换为表格
- arrays - LinkedLists 数组总是给出 NullPointerException
- three.js - BBoxes 不是最佳的 - 在 Autodesk Forge Viewer 中重新计算边界框
- google-data-studio - 如何从嵌入 URL 获取用户令牌?
- sql - SQL改变列和删除约束?
- vue.js - 有没有办法删除连接:来自axios的keep-alive?
- kotlin - 从包中获取参数 null