CodeFest 2018. Rajdeep Varma (badoo) — Application Backdoor via Appium

CodeFest 2018. Rajdeep Varma (badoo) — Application Backdoor via Appium

Посмотрите выступление Rajdeep: https://2018.codefest.ru/lecture/1276/

There's a shift towards open-source mobile test automation tools happening today among developers and QAs. Whether it be Appium, Calabash or anything else: all are good, with some major limitations. While a chosen tool may work well when you first start using it, things can quickly get out of hand with changing business requirements. We started using Calabash at Badoo when there was no Appium. Given the capability of Appium to drive the whole device, we started automation of new apps with Appium. However, we realized a powerful feature was missing in Appium for Android! : The ability to call Application code from automation code like Calabash Backdoors. As Appium UiAutomator server is based on instrumentation, we modified it such that we could instrument our app under test. This gave us the power to access context of Application under test and invoke public methods of Activity using reflection APIs. We use these methods to setup app state, seed DB OR even enable/disable some client-side A/B tests. This makes our application more testable and our tests more predictable. This talk is going to be about how I achieved the above solution and benefits of backdoors.

16b6c87229eaf58768d25ed7b2bbbf52?s=128

CodeFest

April 09, 2018
Tweet

Transcript

  1. Rajdeep Varma Application Backdoor Via Appium

  2. Rajdeep Varma My name is

  3. Up, Up, Down, Down, Left, Right, Left, Right

  4. • Common issues in Mobile test Automation • Solution —

    Backdoors (CheatCodes !) • Demo • How we use Backdoors at Badoo Agenda
  5. Problem #1 FLAKY App

  6. Problem #2 Driver Limits

  7. Problem #2 Weather refreshing every 30 min. How to automate

    this case?
  8. Problem #3 • Firstly, Login takes 30 seconds • And

    Then dismissing “What’s new” takes another 30 sec • I don’t want to repeat this in each test Our tests are so slow.
  9. Appium Backdoors

  10. public class LoginActivity extends Activity {
 
 public void foo()

    {
 // code to set some app state // Or seed DB before test // Or Disable ‘Rate Us’ popup
 }
 }
  11. public class LoginActivity extends Activity {
 
 public void foo()

    {
 // code to set some app state // Or seed DB before test // Or Disable ‘Rate Us’ popup
 }
 } Imagine foo() can be called from automation code def invoke_foo backdoor('foo') end
  12. Demo

  13. • Change Backend URLs • Change App Locale • Getting

    session_id from app • Disable “What’s new” tutorials after login Where do we use Backdoors?
  14. • Disable client side A/B tests • Faking SIM card

    for payments • Get Analytics data from app to validate it Where do we use Backdoors?
  15. How?

  16. Appium Client AppUnderTest apk J S O N W P

    Android Device Automation Code androidTest apk Uiautomator2Server apk
  17. Appium Client AppUnderTest apk J S O N W P

    Android Device Automation Code androidTest apk Uiautomator2Server apk Instrumentation UiAutomator2
  18. Appium Client AppUnderTest apk J S O N W P

    Android Device Automation Code androidTest apk Uiautomator2Server apk Instrumentation UiAutomator2
  19. Appium Client AppUnderTest apk J S O N W P

    Android Device Automation Code UiAutomator2 androidTest apk
  20. Appium Client AppUnderTest apk J S O N W P

    Android Device Automation Code UiAutomator2 androidTest apk Instrumentation
  21. Moving to single uiautomator2 server apk

  22. None
  23. •https://github.com/rajdeepv/appium- uiautomator2-server/tree/single_apk •There is a special backdoor handler in above

    fork •gradle clean assembleServerDebugAndroidTest
  24. <instrumentation android:name= "android.support.test.runner.AndroidJUnitRunner" android:functionalTest="false" android:handleProfiling="false" android:label="Tests for io.appium.uiautomator2.server" android:targetPackage="io.appium.uiautomator2.server" />

    appium-uiautomator2-server-debug-androidTest.apk
  25. <instrumentation android:name= "android.support.test.runner.AndroidJUnitRunner" android:functionalTest="false" android:handleProfiling="false" android:label="Tests for io.appium.uiautomator2.server" android:targetPackage="io.appium.uiautomator2.server" />

    appium-uiautomator2-server-debug-androidTest.apk
  26. <instrumentation android:name= "android.support.test.runner.AndroidJUnitRunner" android:functionalTest="false" android:handleProfiling="false" android:label="Tests for io.appium.uiautomator2.server" android:targetPackage="our.application.package" />

    appium-uiautomator2-server-debug-androidTest.apk
  27. $ gem install 'appium_instrumenter' $ appium_instrumenter instrument my_app.apk This creates

    instrumented copy of server apk in ./test_servers
  28. $ gem install 'appium_instrumenter' $ appium_instrumenter instrument my_app.apk $ adb

    install appium-uiautomator2-server-debug- androidTest.apk $ adb install appium-uiautomator2-server- v0.3.0.apk
  29. On Client side.. curl -X POST -H "Content-Type: application/json" http://localhost:<forwarded_port>/wd/hub/

    session/:sessionId/backdoor -d '{"methods":[{"name":"<method>", "args":["<method_arg>"]}]}'
  30. On Client side.. def backdoor(*args) url = "http://localhost:#{FORWARDED_PORT}"+ “/wd/hub/session/:sessionId/backdoor" body

    = {'methods' => args}.to_json # code to post data end
  31. On Client side.. def backdoor(*args) url = "http://localhost:#{FORWARDED_PORT}"+ “/wd/hub/session/:sessionId/backdoor" body

    = {'methods' => args}.to_json # code to post data end backdoor({name:”methodName",args:["Arg"]})
  32. None
  33. Quiz 1. Add a backdoor method to change refersh interval:

    changeRefreshInterval(time) 2. Add a backdoor method to refresh weather refreshWeather() Weather refresh every 30 min. How will you test this case?
  34. • https://developer.android.com/reference/android/app/Instrumentation.html • https://developer.xamarin.com/guides/testcloud/calabash/working-with/ backdoors/ • https://techblog.badoo.com/blog/2014/10/09/calabash-android-query/ • https://github.com/calabash/calabash-android •

    https://github.com/calabash/calabash-android-server References
  35. Thank you! Rajdeep Varma mail.rajvarma@gmail.com rajdeepv @varmarajdeep