java - Selenium 等到 API 响应
问题描述
我想检查 API 响应,然后单击特定按钮,因此该按钮存在,无需进行可见性检查,但 API 仍在后台检查某些有效性。我的步骤定义是“
@And("^I click on Describe your Shipment button$")
public void i_click_on_describe_your_shipment_button() {
Button.safeClick(driver, destinationLocation.describeYourShipmentButton());}
我努力了:
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
但没有奏效。
唯一对我有用的东西:
Thread.sleep()
我不想使用。有什么建议吗?
解决方案
不知道如何在 Selenium 中解决这个问题,但你可以用Awaitility摆脱那个 Thread.sleep 。
来自他们的 Github 页面的示例:
@Test
public void updatesCustomerStatus() {
// Publish an asynchronous message to a broker (e.g. RabbitMQ):
messageBroker.publishMessage(updateCustomerStatusMessage);
// Awaitility lets you wait until the asynchronous operation completes:
await().atMost(5, SECONDS).until(customerStatusIsUpdated());
...
}
推荐阅读
- c# - “俄罗斯套娃”类 - 读写 XML
- php - PHP Carbon从字符串格式确定日期类型
- python - 在 Python 中的函数中调用函数时遇到问题
- angular - 修改nrwl nx项目中的tsconfig和tslint文件后需要重启VSCode以消除错误
- r - R定义函数以将列作为输入而不是值
- python - 使用 Surprise 构建推荐系统
- nginx - 带有letsencrypt的nginx入口:等待http-01质询传播:错误状态码'404',预期'200'
- vb.net - 如何从多个数据表中填充集合
- python - 如何像 Python 'requests' 库 'response.content' 一样获取 HTML 响应的字节表示
- r - 如何将一个数据框中的行替换为另一个数据框中所有列的匹配行