Mobile automation uamobile

2,612 views
2,671 views

Published on

Published in: Technology
1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total views
2,612
On SlideShare
0
From Embeds
0
Number of Embeds
1,707
Actions
Shares
0
Downloads
18
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Mobile automation uamobile

  1. 1. Автоматизация Тестирования Мобильных Приложений Андрей Дзыня
  2. 2. Andrii DzyniaTest Engineer/Consultant/Trainer @adzynia http://adzynia.com
  3. 3. СегодняПочему я начал заниматься автоматизациеймобильных приложений? Какие есть инструменты?Какие проблемы решены, а какие нет?
  4. 4. Мой опыт
  5. 5. Кто у нас в зале?
  6. 6. Особенность мобильной разработки?
  7. 7. Типы приложений?WebNativeHybridOpenGLFlash & FlexWidgets
  8. 8. • Скорость• Дизайн• Возможности платформы• Кроссплатформенность
  9. 9. Автоматизация UI API Integration Unit
  10. 10. Какие бывают роботы?
  11. 11. ИнструментыMultiplatform tools UI Automation, iPhone Android WebDriver, Native tools WebDriver, NativeDriver, NativeDriver, Robotium, Frank, TAF, KIF, calabash calabash Record’n’play
  12. 12. Дорого и ненадежно
  13. 13. Device Anywhere
  14. 14. Бесплатно и ненадежно @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
  15. 15. Не очень дорого но и не нужно M-eux
  16. 16. Бесплатноно могло быть и лучше
  17. 17. Keep It Functional@implementation KIFTestScenario (EXAdditions)+ (id)scenarioToLogIn;{KIFTestScenario *scenario = [KIFTestScenario scenarioWithDescription:@"Test that auser 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:[KIFTestStepstepToWaitForTappableViewWithAccessibilityLabel:@"Welcome"]];return scenario; }@end https://github.com/square/KIF
  18. 18. UI Automation
  19. 19. Код UI Automation// create a new accounttable.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();
  20. 20. https://github.com/alexvollmer/tuneup_jstest("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());}
  21. 21. Jasminedescribe("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 !"); });});
  22. 22. Jasminehttps://github.com/pivotal/jasmine-iphonehttps://github.com/mczenko/UIAutomation-jasmine-iphonehttps://github.com/shaune/jasmine-ios-acceptance-testshttps://github.com/jhaynie/iphonesimhttps://github.com/robholland/WaxSim
  23. 23. 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
  24. 24. Not maintainedhttp://code.google.com/p/nativedriverSome updateshttps://github.com/sonixlabs/nativedriverhttps://github.com/leandog/nativedriverRuby APIhttps://github.com/jarib/nativedriver-rb
  25. 25. EPAM-Mobile-TAFhttps://github.com/EPAM-Systems/EPAM-Mobile-TAF
  26. 26. TAF Java Code@BeforeClasspublic 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);}
  27. 27. Behavior DrivenFeature: Various scenarios that exercise different partsof FrankScenario: Scrolling to the bottom of the tableGiven I launch the appWhen I touch "Larry Stooge"And I touch "User Roles"Then I should not see "Returns"When I scroll to the bottom of the tableThen I should see "Returns"
  28. 28. Step DefinitionWhen /^I touch the "([^"]*)" nav bar button$/do |mark| touch( "navigationButton marked:#{mark}" )end
  29. 29. Frameworkshttps://github.com/robholland/icukehttps://github.com/moredip/Frankhttps://github.com/calabash/calabash-ioshttp://cukes.info/https://github.com/cucumber/cucumber-jvmhttps://github.com/baalexander/Mother-May-UI
  30. 30. BDD is Behavior Driven not Test Steps Driven
  31. 31. Jenkinshttps://wiki.jenkins-ci.org/display/JENKINS/iOS+Device+Connector+Plugin
  32. 32. Android Testinghttp://developer.android.com/tools/testing/testing_android.html
  33. 33. Using Android SDKНажатия на View• TouchUtils.tapView(view)Нажатия на кнопки• getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU)Ввод текста• sendKey(“some text”)
  34. 34. Activity Test@UiThreadTestpublic 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");}
  35. 35. В чем проблема? Очень частоНужно знать структуру приходится добавлятькода приложения Thread.sleep(3000)Большие приложения Тесты выполняютсяавтоматизировать очень долгоочень сложно
  36. 36. Robotium APIgetCurrentActivity()clickOnButton(String regex)clickInList(int line)enterText(int index, String text)searchText(String regex)waitForText(), waitForActivity(), waitForView()clickOnMenuItem(String text)goBack(), goBackToActivity(String name)
  37. 37. Robotiumpublic 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/robotium")); } http://code.google.com/p/robotium/
  38. 38. Robotium with WebViewprivate 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
  39. 39. Robotium выводыАвтоматические jUnit 3ожидания Работает только сАвтоматический поиск однопроцесснымиView приложениямиАвтоматическое Требует базовое Activityпереключение на Activity для работыСам принимает решения,например scroll
  40. 40. Запуск тестов in Parallel или in Cloudhttp://testdroid.com/product/testdroid-server http://testdroid.com/product/testdroid-cloud
  41. 41. Jenkins https://wiki.jenkins-ci.org/display/JENKINS/Android+Emulator+Pluginhttps://wiki.jenkins-ci.org/display/JENKINS/Building+an+Android+app+and+test+project
  42. 42. Helper Toolshttp://developer.android.com/tools/help/hierarchy-viewer.htmlhttp://developer.android.com/tools/help/monkey.htmlhttps://github.com/robomorphine/testrunner
  43. 43. 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/nativedriverhttps://github.com/alfredz/android-nativedriver
  44. 44. ANDROID UI APIUiScrollable settingsItem = newUiScrollable(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
  45. 45. Monkey Runner Pythondevice = MonkeyRunner.waitForConnection()package = com.example.android.notepaddevice.wake()device.shell("am start -a android.intent.action.INSERT -tvnd.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
  46. 46. Monkey Runner Extensiondef 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
  47. 47. Other Android Toolshttp://developer.android.com/tools/help/monkey.htmlhttps://github.com/calabash/calabash-androidhttps://github.com/eing/moethttp://www.ranorex.com/mobile-automation-testing/android-test-automation.htmlhttps://github.com/kaeppler/calculonhttps://github.com/pivotal/robolectrichttps://www.lesspainful.com/
  48. 48. Demo
  49. 49. For Web Applications
  50. 50. Selenium WebDriverpublic 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();}
  51. 51. Сегодня узналиКакие есть инструменты для UIавтоматизации тестирования:• iOS приложений• Android приложенийКакие стоит использовать, а какие нет
  52. 52. http://adzynia.com @adzynia me@adzynia.com

×