gpt4 book ai didi

android - robotium中有没有类似pagefactory的模式?

转载 作者:行者123 更新时间:2023-11-29 15:22:15 25 4
gpt4 key购买 nike

我正在尝试使用 robotium 为我们的 Android 应用程序构建自动化测试用例环境。虽然 robotium 现在可以运行,但我仍然对如何使测试用例更简洁或更有条理感到困惑。现在测试用例看起来非常复杂和困惑。当我使用 selenium 时,有一个 pagefactory 模式。

robotium中有类似的东西吗?

最佳答案

首先,您需要区分这两种模式,Page ObjectPage Factory

  • Page Object 模式是通过创建表示网页的类(或移动应用程序中的等效类)来实现的).
  • Page Factory 模式是 Page Object 和 <我 Abstract Factory 模式。 Selenium 确实带有用于实现 PageObject Factory 模式的类,但实现可能很棘手且容易出错,而且我和我的同事都没有发现使用它是可取的。

    /li>

既然 Page Object 模式是您真正想要的,我将向您展示我和我的同事为实现该模式而想出的一些方法在 Robotium 中。

在 Robotium 中,Selenium WebDriver 的粗略等价物是 Solo 类。它基本上是一个 decorator一次用于一堆其他对象(您可以在 GitHub Repository 中看到所有涉及的类的列表)。

要使用 Robotium Solo 对象实现页面对象模式,首先从一个带有 Solo 字段的抽象页面对象开始(就像在 Selenium 中,您会有一个 WebDriver 字段)。

public abstract class AppPage {

private Solo solo;

public AppPage(Solo solo) {
this.solo = solo;
}

public Solo getSolo() {
return this.solo;
}
}

然后,为每个页面扩展 AppPage,如下所示:

public class MainPage extends AppPage {

public MainPage(Solo solo) {
super(solo);
}

// It is useful to be able to chain methods together.

// For public methods that direct you to other pages,
// return the Page Object for that page.
public OptionsPage options() {
getSolo().clickOnButton(getSolo().getString(R.string.options_button));
return new OptionsPage(getSolo());
}

//For public methods that DON'T direct you to other pages, return this.
public MainPage searchEntries(String searchWord) {
EditText search = (EditText) solo.getView(R.id.search_field);
solo.enterText(search, searchWord);
return this;
}
}

在 Robotium 中实现页面对象模式时,您可以做很多奇特的事情,但这会让您朝着正确的方向开始。

关于android - robotium中有没有类似pagefactory的模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17272026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com