67

Magneto - Android Test Automation

Embed Size (px)

Citation preview

Page 1: Magneto - Android Test Automation
Page 2: Magneto - Android Test Automation

Android Automation next level sh****t

Page 3: Magneto - Android Test Automation

Heyo!I’M RAN BEN AHARON

Android & Automation lead @EverythingMe

[email protected]

Page 4: Magneto - Android Test Automation
Page 5: Magneto - Android Test Automation

Pain

Mobile development is not easy

Page 6: Magneto - Android Test Automation

FIXED A TYPO

NOW APP CRASHES IN PRODUCTION

Page 7: Magneto - Android Test Automation

RELEASE DAY

SCARED SHITLESS

Page 8: Magneto - Android Test Automation

DREAMED OFBUILDING APPS

NOW I CAN’T SLEEP

Page 9: Magneto - Android Test Automation

“In order to move fast - you need good brakes

Page 10: Magneto - Android Test Automation

We love open source

at EverythingMe we utilize, create and contribute

Page 13: Magneto - Android Test Automation

Struggling to make it work

Gaining and maintaining trust

Page 14: Magneto - Android Test Automation

Distrust and disengagement

Unreliable resultsNot part of the release flowNo visibilityCumbersome tools

Page 15: Magneto - Android Test Automation

Trust and cooperation

Reliable resultsPart of the release flowFull visibilityDelightful tools

Page 16: Magneto - Android Test Automation
Page 17: Magneto - Android Test Automation

We’re hiring anAutomation engineer

?

Page 18: Magneto - Android Test Automation

Page 19: Magneto - Android Test Automation

What’s so special about

Yet another UI testing FW?

Page 20: Magneto - Android Test Automation

Fits our needs

FasterLeanerReliable resultsPython goodnessLots of essential test methods

Page 21: Magneto - Android Test Automation

1.Setup was a big hassle

Page 22: Magneto - Android Test Automation

1.Setup was a big hassle

Magneto is easy to install and run

Page 23: Magneto - Android Test Automation

$ pip install magneto

Install

$ magneto run [tests_path]

Run

Boilerplate

$ magneto init [package]

Page 24: Magneto - Android Test Automation

Example test

def test_button(self): # and click button button = self.magneto(text='Click me') button.click()

# scroll list list = self.magneto(className='android.widget.ListView') list.fling.toEnd()

# make sure last item exists last_item = self.magneto(text="last item") Assert.true(last_item.exists)

Page 25: Magneto - Android Test Automation

2.Time sleeps causedflaky results

Page 26: Magneto - Android Test Automation

2.Time sleeps causedflaky results

Magneto is truly ready for async

Page 27: Magneto - Android Test Automation

wait_for_element

wait for an element to appear

Page 28: Magneto - Android Test Automation

# wait for button button = self.magneto.wait_for_element(text=’click’) # make sure it’s there Assert.true(button.exists)

wait for button to appear

Page 29: Magneto - Android Test Automation

wait_for_true

wait for a function to return True

Page 30: Magneto - Android Test Automation

# click button self.magneto(text=’Click me’).click()

# wait for text to change self.magneto.wait_for_true(lambda: button.info[‘text’] != ‘Click me’ )

wait for button text to change

Page 31: Magneto - Android Test Automation

Assert.current_package

wait for package to focus

Page 32: Magneto - Android Test Automation

# tap chrome icon self.magneto(text=’Chrome’).click() # wait for chrome to open Assert.current_package(‘com.android.chrome’)

wait for chrome to open

Page 33: Magneto - Android Test Automation

ADBLogWatch

Tune in to logcat

Page 34: Magneto - Android Test Automation

# install app with ADBLogWatch() as w: w.watch(‘android.intent.action.PACKAGE_ADDED’) ADB.install(‘apps/facebook.apk’) w.assert_done()

# make sure it’s on homescreen app = self.magneto(text=’Facebook’) Assert.true(app.exists)

wait for app to be installed

Page 35: Magneto - Android Test Automation

3.Stats were hard to trace

Page 36: Magneto - Android Test Automation

3.Stats were hard to trace

Using logcat for immediate feedback

Page 37: Magneto - Android Test Automation

# click button with ADBLogWatch() as w: w.watch(‘Stat1 sent’)

self.magneto(text=’click’).click() w.assert_done()

assert stat

Page 38: Magneto - Android Test Automation

# click button with ADBLogWatch() as w: w.watch(‘Stat1 sent’) w.watch(‘Stat2 sent’)

self.magneto(text=’click’).click() w.assert_done()

assert multiple stats

Page 39: Magneto - Android Test Automation

# click button with ADBLogWatch() as w: w.watch(‘Stat sent’,screen=’home’,action=’click')

self.magneto(text=’click’).click() w.assert_done()

assert stat params

Page 40: Magneto - Android Test Automation

4.Failed tests were unclear

Page 41: Magneto - Android Test Automation

4.Failed tests were unclear

Magneto supplies screenshots, videos...

Page 42: Magneto - Android Test Automation

$ magneto run --save-data-on-failure

Save test fail data

Page 43: Magneto - Android Test Automation

$ magneto run --save-data-on-failure --include-video-on-failure

Save test fail data

Page 44: Magneto - Android Test Automation

- 3-test_name-time.hierarchy.uix- 3-test_name-time.screenshot.png- 3-test_name-time.logcat.log- 3-test_name-time.video.mp4

- 12-test_name-time.hierarchy.uix- 12-test_name-time.screenshot.png- 12-test_name-time.logcat.log- 12-test_name-time.video.mp4

Failed tests artifacts

Page 45: Magneto - Android Test Automation

5.Device miscommunication

Page 46: Magneto - Android Test Automation

5.Device miscommunication

Magneto gives you ADB power

Page 47: Magneto - Android Test Automation

ADB.install(apk_path)ADB.uninstall(app_package)ADB.start_activity(app_package, app_activity)ADB.kill_process(app_package)

ADB.exec_cmd(command)ADB.set_date(date)ADB.getprop(prop)ADB.get_log()ADB.clear_log()

ADB power

Page 48: Magneto - Android Test Automation

6.Painful debugging

Page 49: Magneto - Android Test Automation

6.Painful debugging

iMagneto + UiAutomatorViewer

Page 50: Magneto - Android Test Automation

$ imagneto

In magneto(text=”click”).click()In magneto.orientation = “r”

In f = magneto(resourceId=”el”)In f.info

imagneto

Page 51: Magneto - Android Test Automation

Much more!

Skipping, tagging, blockingFragmentation handling

Page 52: Magneto - Android Test Automation

The FUTURE

It’s gonna get osom

Page 53: Magneto - Android Test Automation

Fail on GC

Page 54: Magneto - Android Test Automation

Fail on log > n

Page 55: Magneto - Android Test Automation

Web inspector?

Page 56: Magneto - Android Test Automation

Non-active windows

Page 57: Magneto - Android Test Automation

Docs

Page 58: Magneto - Android Test Automation

Known limitations

○ Android 4.2+○ Sequential UI actions only

Page 59: Magneto - Android Test Automation

FORK and CONTRIBUTE

http://github.com/EverythingMe/magneto

Page 60: Magneto - Android Test Automation

“http://mobileautomators.com

Page 61: Magneto - Android Test Automation

We’re Hiring!

Page 62: Magneto - Android Test Automation

We’re Hiring!Experienced Android Dev

Page 63: Magneto - Android Test Automation

We’re Hiring!Experienced Android Dev

Automation Engineer

Page 64: Magneto - Android Test Automation

We’re Hiring!Experienced Android Dev

Automation Engineer

[email protected]

Page 65: Magneto - Android Test Automation

Come talk to usExperienced Android Dev

Automation Engineer

[email protected]

Page 66: Magneto - Android Test Automation
Page 67: Magneto - Android Test Automation

THANKS!Any questions?

[email protected]