我目前正在尝试使用Java在Selenium中运行一个脚本,该脚本不知道哪个页面加载。有一个嵌入其中的JSON字段,我试图用它来告诉我的脚本哪个部分已加载以运行正确的测试。问题是除了其中一个字段的一部分外,所有JSON值都是相同的。
以下是拉出的三个JSON值:
NULL
唯一的区别是taskDisplayName中的Test和Fulfillment之间的数字。
我目前正在尝试使用以下方法按其加载的顺序运行:
value="{"formType":"taskExecutuion","orderId":"111111","userId":"222","assigneeId":"333","taskId":"44444","taskName":"Order Entry Review by Listing","taskDisplayName":"AAAA 1234569999 Same for All Test 1 Fulfillment 666666"}"
value="{"formType":"taskExecutuion","orderId":"111111","userId":"222","assigneeId":"333","taskId":"44444","taskName":"Order Entry Review by Listing","taskDisplayName":"AAAA 1234569999 Same for All Test 2 Fulfillment 666666"}"
value="{"formType":"taskExecutuion","orderId":"111111","userId":"222","assigneeId":"333","taskId":"44444","taskName":"Order Entry Review by Listing","taskDisplayName":"AAAA 1234569999 Same for All Test 3 Fulfillment 666666"}"
如果有人能帮助我弄清楚为什么它会跳过这三个并且在这三个之后进行下一次测试甚至没有看,我会很感激。
使用以下语言编写脚本:
int spr = 0;
do {
Thread.sleep(10000);
WebElement task_name = driver.findElement(By.xpath("id('test')"));
String task_name_values = task_name.getAttribute("value");
Object obj = null;
try {
obj = parser.parse(task_name_values);
} catch (ParseException e) {
e.printStackTrace();
}
JSONObject fulfill = (JSONObject)obj;
String fulfillment_form_confirm = (String) fulfill.get("taskDisplayName");
if (fulfillment_form_confirm.contains("Test 1")){
testRun.testSample1(driver);
} else if (fulfillment_form_confirm.contains("Test 2")){
testRun.testSample2(driver);
} else if (fulfillment_form_confirm.contains("Test 3")){
testRun.testSample3(driver);
} else break;
spr++;
System.out.print(spr + "\n");
} while (spr == 2);
已插入,这是返回的值:
AAAA 1234569999同样适用于所有测试1履行666666
有趣的是,它确实通过do while循环首次注册,但随后退出而没有通过其他两次就像它应该有