英文:
How can I make a delay in the test so that the page is fully loaded?
问题
我使用 [io.qameta.atlas](https://github.com/qameta/atlas),在测试完第一个复选框后,如何添加延迟?以下是测试代码:
```java
@Test
public void produrtTest(){
onSite().onMainPage().getButton().findElement(By.xpath("//[@id=\"-category-section\"]/div/ul/li[1]/label/span")).click();
onSite().onMainPage().getButton().findElement(By.xpath("//[@id=\"-category-section\"]/div/ul/li[2]/label/span")).click();
}
我使用了 @Retry
注解(timeout = 20, polling = 5000
)来等待页面加载,但没有暂停效果。
如何使用 waitUntil()
方法也不太清楚。
<details>
<summary>英文:</summary>
I use [io.qameta.atlas](https://github.com/qameta/atlas), how do I make a delay after testing the first checkbox? Here's the test:
@Test
public void produrtTest(){
onSite().onMainPage().getButton().findElement(By.xpath("//[@id="-category-section"]/div/ul/li[1]/label/span")).click();
onSite().onMainPage().getButton().findElement(By.xpath("//[@id="-
category-section"]/div/ul/li[2]/label/span")).click();
}
I used the `@Retry annotation(timeout = 20, polling = 5000)` to wait 20 seconds for the page to load, but there is no pause.
How to use the waitUntil () method is also unclear.
</details>
# 答案1
**得分**: 1
在您正在使用的工具的[首页](https://github.com/qameta/atlas)上有这样一个部分:
> **等待页面加载。** 有一个特殊的 shouldUrl(Matcher<String>
> url),它等待页面当前的URL和
> document.readyState 标志的条件。
```java
@BaseUrl("http://www.base.url/search")
public interface SearchPage extends WebPage {
@Description("账户按钮")
@FindBy("//div[@class = 'account-button']")
AtlasWebElement accountButton();
}
@BaseUrl("http://www.base.url/account")
public interface AccountPage extends WebPage {
//账户页面的元素在这里
}
以及
等待单个元素的条件。 AtlasWebElement 有两种不同的扩展方法用于等待。
第一种 - waitUntil(Matcher matcher),它在可配置的超时和传递的匹配器中等待,如果条件未满足,则抛出 java.lang.RuntimeException。
第二种 - should(Matcher matcher),以相同的方式在传递的匹配器上等待,但抛出 java.lang.AssertionError。
这两种方法中的一种应该能满足您的需求,具体取决于您等待什么(您没有指定)。
英文:
At the very front page of the tool you are using there's this section:
> Waiting for page loading. There is a special shouldUrl(Matcher<String>
> url) that waits on the condition for page’s current url and
> document.readyState flag.
@BaseUrl("http://www.base.url/search")
public interface SearchPage extends WebPage {
@Description("Account button")
@FindBy("//div[@class = 'account-button']")
AtlasWebElement accountButton();
}
@BaseUrl("http://www.base.url/account")
public interface AccountPage extends WebPage {
//elements for account page here
}
As well as
> Waiting on a condition for a single element. AtlasWebElement have two
> different extension methods for waiting.
>
> First - waitUntil(Matcher matcher) which waits with a configurable
> timeout and polling on some condition in a passed matcher, throwing
> java.lang.RuntimeException if condition has not been satisfied.
>
> Second - should(Matcher matcher) which waits the same way on a passed
> matcher, but throwing java.lang.AssertionError instead.
One of those should satisfy your need, depending on what you're waiting for (you did not specify).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论