Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Автоматизация Тестирования
  Мобильных Приложений
      Андрей Дзыня
Andrii Dzynia
Test Engineer/Consultant/Trainer



                @adzynia




         http://adzynia.com
Сегодня

Почему я начал заниматься автоматизацией
мобильных приложений?


  Какие есть инструменты?


Какие проблемы решены, а какие нет?
Мой опыт
Кто у нас в зале?
Особенность мобильной
     разработки?
Mobile automation uamobile
Типы приложений?
Web

Native

Hybrid

OpenGL

Flash & Flex

Widgets
Mobile automation uamobile
Mobile automation uamobile
• Скорость

• Дизайн

• Возможности платформы

• Кроссплатформенность
Автоматизация

     UI

    API
 Integration
    Unit
Какие бывают роботы?
Инструменты



Multiplatform tools
                       UI Automation, iPhone       Android WebDriver,
   Native tools       WebDriver, NativeDriver,    NativeDriver, Robotium,
                      Frank, TAF, KIF, calabash          calabash



  Record’n’play
Дорого и ненадежно
Device Anywhere
Mobile automation uamobile
Бесплатно и ненадежно
  @Test
   public void testFindInROI() throws Exception {
    JButtons frame = new JButtons();
    Screen scr = new Screen();
        Match m = scr.wait("test-res/network.png", 10);
        scr.setRect(new Rectangle(m.x-9, m.y-10, m.w+10, m.h+11));
        Match m2 = scr.doFind("test-res/network.png");
        assertEquals(m, m2);
        frame.dispose();
    }




https://github.com/sikuli/sikuli
Не очень дорого но и не нужно


                  M-eux
Mobile automation uamobile
Бесплатно

но могло быть и лучше
Keep It Functional
@implementation KIFTestScenario (EXAdditions)

+ (id)scenarioToLogIn;
{
KIFTestScenario *scenario = [KIFTestScenario scenarioWithDescription:@"Test that a
user can successfully log in."];
[scenario addStep:[KIFTestStep stepToReset]];
[scenario addStepsFromArray:[KIFTestStep stepsToGoToLoginPage]];
[scenario addStep:[KIFTestStep stepToEnterText:@"user@example.com"
intoViewWithAccessibilityLabel:@"Login User Name"]];
[scenario addStep:[KIFTestStep stepToTapViewWithAccessibilityLabel:@"Log In"]];
// Verify that the login succeeded
[scenario addStep:[KIFTestStep
stepToWaitForTappableViewWithAccessibilityLabel:@"Welcome"]];

return scenario; }

@end
                                                https://github.com/square/KIF
UI Automation
Код UI Automation
// create a new account
table.cells().firstWithName("twitter").tap();
mainWindow = app.mainWindow();
table = mainWindow.tableViews()[0];

userName = table.cells().firstWithName("user name");
userName.textFields()[0].setValue("mrfoobar");
finish = table.cells().firstWithName("finish");

finish.tap();
https://github.com/alexvollmer/tuneup_js
test("my test", function(target, app) { {

    mainWindow = app.mainWindow();
    tableViews = mainWindow.tableViews();
    assertEquals(1, tableViews.length);
    table = tableViews[0];

    assertEquals("First Name",
    table.groups()[0].staticTexts()[0].name());
    assertEquals("Last Name",
    table.groups()[1].staticTexts()[0].name());

    assertEquals("Fred", table.cells()[0].name());
    assertEquals("Flintstone", table.cells()[1].name());
}
Jasmine
describe("Hello World App", function() {{
      var target = UIATarget.localTarget();
      function getLabel() { {
      return target.frontMostApp().
      mainWindow().staticTexts()[0].value(); }

      it("should display "Hello World !" in the label after pressing
      the "Click Me :)" button",
      function() { target.frontMostApp().
      mainWindow().buttons()["Click Me :)"].tap();

      expect(getLabel()).toEqual("Hello World !"); });
});
Jasmine
https://github.com/pivotal/jasmine-iphone
https://github.com/mczenko/UIAutomation-
jasmine-iphone
https://github.com/shaune/jasmine-ios-
acceptance-tests
https://github.com/jhaynie/iphonesim
https://github.com/robholland/WaxSim
iOS Native Driver Java Test
  public void testNativeDriver() throws Exception {
    WebDriver driver = new IosNativeDriver();
    driver.manage().timeouts().implicitlyWait(10,
    TimeUnit.SECONDS);

      // Type user name
      WebElement userName =
      driver.findElement(By.placeholder("User Name"));
      userName.clear();
      userName.sendKeys("NativeDriver");
  }

http://code.google.com/p/nativedriver
Not maintained
http://code.google.com/p/nativedriver

Some updates
https://github.com/sonixlabs/nativedriver
https://github.com/leandog/nativedriver

Ruby API
https://github.com/jarib/nativedriver-rb
EPAM-Mobile-TAF




https://github.com/EPAM-Systems/EPAM-Mobile-TAF
TAF Java Code
@BeforeClass
public static void beforeAll() {
         logger = TAFLoggerFactory.
         getLogger(ProjectExampleSmokeTestSet.class);
         setUpAllTests();
}

@Test(timeout = test_timeout)
@TestFixture(username=test_desktop_user, password=test_desktop_pass)
public void isAuthenticateLogin() {
    expecteds = AppModel.HomeScreen.getScreenModel();
    actuals = ScreenFactory.getInstance().getLoginScreen(). login(username,
    password).getScreenModel();

    Assert.assertArrayEquals(expecteds, actuals);
}
Behavior Driven
Feature: Various scenarios that exercise different parts
of Frank

Scenario: Scrolling to the bottom of the table

Given I launch the app
When I touch "Larry Stooge"
And I touch "User Roles"
Then I should not see "Returns"
When I scroll to the bottom of the table
Then I should see "Returns"
Step Definition


When /^I touch the "([^"]*)" nav bar button$/
do |mark|
 touch( "navigationButton marked:'#{mark}'" )
end
Frameworks

https://github.com/robholland/icuke
https://github.com/moredip/Frank
https://github.com/calabash/calabash-ios
http://cukes.info/
https://github.com/cucumber/cucumber-jvm
https://github.com/baalexander/Mother-May-UI
BDD is Behavior Driven
 not Test Steps Driven
Jenkins




https://wiki.jenkins-ci.org/display/JENKINS/iOS+Device+Connector+Plugin
Mobile automation uamobile
Android Testing




http://developer.android.com/tools/testing/testing_android.html
Using Android SDK

Нажатия на View
• TouchUtils.tapView(view)

Нажатия на кнопки
• getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU)

Ввод текста
• sendKey(“some text”)
Activity Test
@UiThreadTest
public void testAdd() {
    MainActivity main = (MainActivity) getActivity();
    EditText val1Edit = (EditText) main.findViewById(R.id.EditText1);
    val1Edit.setText("3");

     EditText val2Edit = (EditText) main.findViewById(R.id.EditText2);
    val2Edit.setText("4");

    Button addButton = (Button) main.findViewById(R.id.ButtonAdd);
    addButton.performClick();

    TextView resultText = (TextView) main.findViewById(R.id.Result);
    assertEquals("Result incorrect", resultText.getText(), "7");
}
В чем проблема?


                        Очень часто
Нужно знать структуру
                        приходится добавлять
кода приложения
                        Thread.sleep(3000)

Большие приложения
                        Тесты выполняются
автоматизировать
                        очень долго
очень сложно
Robotium API
getCurrentActivity()
clickOnButton(String regex)
clickInList(int line)
enterText(int index, String text)
searchText(String regex)
waitForText(), waitForActivity(), waitForView()
clickOnMenuItem(String text)
goBack(), goBackToActivity(String name)
Robotium
public void testPreferenceIsSaved() throws Exception {
       solo.sendKey(Solo.MENU);
       solo.clickOnText("Preferences");
       solo.clickOnText("Edit File Extensions");
       Assert.assertTrue(solo.searchText("rtf"));

      solo.clickOnText("txt");
      solo.clearEditText(2);
      solo.enterText(2, "robotium");
      solo.clickOnButton("Save");
      solo.goBack();
      solo.clickOnText("Edit File Extensions");
      Assert.assertTrue(solo.searchText("application/rob
otium")); }
                                 http://code.google.com/p/robotium/
Robotium with WebView
private ExtSolo solo;

public void setUp() throws Exception {
    super.setUp();
    solo = new ExtSolo(getInstrumentation(), getActivity(),
    this.getClass().getCanonicalName(), getName());
}

public void test() {
    solo.clickOnHtmlElement(“userName”);
    solo.enterTextIntoHtmlElement(“User”, ”userName”);
    solo.htmlGoBack();
}
                              http://docs.testdroid.com/_pages/extsolo.html
Robotium выводы


Автоматические                              jUnit 3
ожидания                         Работает только с
Автоматический поиск            однопроцессными
View                               приложениями
Автоматическое             Требует базовое Activity
переключение на Activity               для работы
Сам принимает решения,
например scroll
Запуск тестов in Parallel или in Cloud




http://testdroid.com/product/testdroid-server


                                           http://testdroid.com/product/testdroid-cloud
Jenkins




   https://wiki.jenkins-ci.org/display/JENKINS/Android+Emulator+Plugin
https://wiki.jenkins-ci.org/display/JENKINS/Building+an+Android+app+and+test+project
Helper Tools
http://developer.android.com/tools/help/hierar
chy-viewer.html
http://developer.android.com/tools/help/monk
ey.html
https://github.com/robomorphine/testrunner
Android Native Driver Java Test
    private AndroidNativeDriver driver;
    @Override
    protected void setUp() {
                 driver = getDriver();
    }

    @Override
    protected void tearDown() {
                 driver.quit();
    }

    protected AndroidNativeDriver getDriver() {
                return new AndroidNativeDriverBuilder().withDefaultServer().build();
    }

    private void startListViewActivity() {
                  driver.startActivity("com.google.android.testing.nativedriver." + "simplelayouts.ListViewActivity");
    }

    public void testClickListItems_scrollsGradually() {
                  startListViewActivity();
                  for (String state : states) {
                  driver.findElement(AndroidNativeBy.text(state)).click();
    }}
                                                                             http://code.google.com/p/nativedriver
https://github.com/alfredz/android-nativedriver
ANDROID UI API
UiScrollable settingsItem = new
UiScrollable(new UiSelector()
.className("android.widget.ListView"));

UiObject about =
settingsItem.getChildByText(new UiSelector()
.className("android.widget.LinearLayout"),
"About tablet");
about.click()
           http://developer.android.com/tools/testing/testing_ui.html
          http://developer.android.com/tools/help/uiautomator/index.html
Monkey Runner Python
device = MonkeyRunner.waitForConnection()
package = 'com.example.android.notepad'
device.wake()

device.shell("am start -a android.intent.action.INSERT -t
vnd.android.cursor.dir/contact -e name 'Vasya Pupkin' -e phone 555-
1111")

device.startActivity(component="com.android.contacts/.TwelveKeyDialer")

device.installPackage('d:NotePadTraining.apk')

device.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP)
device.type("asdsadsad")

  http://developer.android.com/tools/help/monkeyrunner_concepts.html
Monkey Runner Extension
def testViewFactory_TextView(self):
    attrs = {'class': 'android.widget.EditText', 'text:mText':
    'Button with ID'}
    view = View.factory(attrs, None, -1)
    self.assertTrue(isinstance(view, EditText))




https://github.com/dtmilano/AndroidViewClient
Other Android Tools
http://developer.android.com/tools/help/monkey.html
https://github.com/calabash/calabash-android

https://github.com/eing/moet
http://www.ranorex.com/mobile-automation-
testing/android-test-automation.html

https://github.com/kaeppler/calculon
https://github.com/pivotal/robolectric

https://www.lesspainful.com/
Demo
For Web Applications
Selenium WebDriver
public void testGoogle() throws Exception {

        WebDriver driver =
        new AndroidDriver()          or IPhoneDriver();
        driver.get("http://www.google.com");

        WebElement element =
        driver.findElement(By.name("q"));

        element.sendKeys("Cheese!");
        element.submit();

        driver.quit();
}
Сегодня узнали

Какие есть инструменты для UI
автоматизации тестирования:
• iOS приложений
• Android приложений
Какие стоит использовать, а какие нет
http://adzynia.com




   @adzynia


  me@adzynia.com

More Related Content

Mobile automation uamobile