本文介绍了有没有像在robotium pagefactory任何模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我米试图通过使用robotium来为我们的Andr​​oid应用程序自动化测试用例环境。虽然robotium可以马上跑,我还在困惑如何使测试用例更简洁的或有组织的。现在测试用例似乎非常复杂和混乱。
当我使用硒,有一个pagefactory模式。

I m trying to build an automation test case environment for our Android application by using robotium. Although robotium could run right now, I'm still confused about how to make the test case more brief or organized. Now the test case seems very complicated and chaotic.When I use selenium, there's a pagefactory pattern.

有没有像在robotium什么?

Is there anything like that in robotium?

推荐答案

首先,你需要在两种模式之间的区别, 页面对象 页厂

  • 页面对象 的模式是通过使该重新present类实现网页(或在MOBLE应用的equivilent)。
  • 页厂 的模式是 页面对象的组合 模式。硒不来带班实施 PageObject厂的格局,但实现可能会非常棘手和容易出错的,我的同事和我还没有找到它需要使用。

    First, you need to differentiate between the two patterns, Page Object and Page Factory.

    • The Page Object pattern is implemented by making classes that represent web pages (or the equivilent in a moble app).
    • The Page Factory pattern is a combination of the Page Object and Abstract Factory patterns. Selenium does come with classes to implement a PageObject Factory pattern, but implementation can be tricky and bug-prone, and my coworkers and I have not found it desirable to use.

      所以,因为 页面对象 的模式是你真正想要的是什么,我会告诉你我的一些同事什么,我都拿出来实施这个模式在Robotium。

      So, since the Page Object pattern is what you really want, I'll show you some of what my coworkers and I have come up with to implement this pattern in Robotium.

      在Robotium,硒的webdriver粗糙equivilent是独奏类。它基本上是在一次一堆其他对象的(你可以看到所有相关类的列表中的GitHub存储库)。

      In Robotium, the rough equivilent of the Selenium WebDriver is the Solo class. It's basically a decorator for a bunch of other objects at once (you can see a list of all the involved classes in the GitHub Repository).

      要实现与Robotium独奏对象Page对象的模式,先用一个个领域的抽象页面对象开始(如硒,你将有一个现场的webdriver)。

      To implement a Page Object pattern with the Robotium Solo object, first start with an abstract Page Object with a Solo field (like in Selenium where you would have a WebDriver field).

      public abstract class AppPage {
      
          private Solo solo;
      
          public AppPage(Solo solo) {
              this.solo = solo;
          }
      
          public Solo getSolo() {
              return this.solo;
          }   
      }
      

      然后,延长AppPage的每一页,就像这样:

      Then, extend AppPage for each page, like so:

      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页面对象的模式,当你能做到的,但是这将让你在正确的方向开始。

      There are a lot more fancy things you can do when implementing a Page Object pattern in Robotium, but this will get you started in the right direction.

      这篇关于有没有像在robotium pagefactory任何模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 18:07