Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 37 ยท Projects and Practice

Practice Exercises and Review Questions

Test what you learned: hands-on exercises, debugging drills with broken Appium code, design questions for suites and device farms, and interview-style review.

Reading about mobile automation is not the same as doing it. This final lesson gives you exercises to build skill: small coding tasks, drills where you find the mistake in broken Appium code, design questions about suites and device farms, and a bank of review questions with short answers. Work through them without looking at earlier lessons first; then check.

Appium and devices cannot run on this site, so the exercises either use read-only Appium code you read and fix on paper, or runnable stand-ins whose logic you can complete and run here.

Part 1: Coding exercises (runnable)

Exercise 1: validate capabilities

Complete check() so it reports a missing appium: prefix, a missing platformName, and an Android session that has neither appium:app nor appium:appPackage with appium:appActivity. Run it; the three cases below should print the problems shown in the comments.

Python Exercise 1: capability validator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Exercise 2: a retrying wait

Write wait_until(condition, attempts, on_fail) that calls condition() up to attempts times, returns the value as soon as it is truthy, and otherwise raises TimeoutError with a message. Extend it with a list that records how many attempts were needed.

Python Exercise 2: wait with a message

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Exercise 3: group failures by device

You get results as (test, device, passed) tuples. Print, for each device, the pass rate and the tests that failed. Then answer: which device looks like it has an environment problem?

Python Exercise 3: failures per device

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Part 2: Find the bug (read-only)

Each snippet has a mistake. Decide what it is before reading the answer list below.

Python
# A
options.set_capability("deviceName", "Pixel_8")
Python
# B
driver.implicitly_wait(30)
WebDriverWait(driver, 10).until(EC.visibility_of_element_located(LOCATOR))
Python
# C
@pytest.fixture
def driver():
    drv = webdriver.Remote(URL, options=options)
    yield drv
Python
# D
driver.find_element(AppiumBy.XPATH, "//android.widget.Button[3]").click()
Python
# E
driver.switch_to.context("WEBVIEW_12345.1")
Python
# F
ActionChains(driver).move_to_element(menu)

Answers:

  • A: the key needs the appium: prefix (appium:deviceName), or use the options class property.
  • B: mixing implicit and explicit waits makes timing unpredictable; keep the implicit wait at 0.
  • C: there is no drv.quit() after the yield, so every test leaks a session.
  • D: an index-based XPath breaks when the layout changes and is slow; use an accessibility ID.
  • E: the iOS WebView name has a changing number; pick it from driver.contexts at run time.
  • F: the chain is never run; it needs .perform() (this is a Selenium rule that also applies to Appium when you use ActionChains; for mobile gestures prefer mobile: commands).

Part 3: Design questions

Write your answers on paper, then compare with the lesson named in brackets.

  1. Your login test passes locally but fails on the cloud device. List five differences you would investigate. [Connecting to a Cloud Grid]
  2. A suite of 240 tests takes 4 hours on one device. You can afford five parallel devices. Estimate the new wall-clock time and explain what could make it worse. [Parallel Runs and the Device Matrix]
  3. Which tests would you run on emulators for every pull request, and which on real devices before release? [Cloud Device Farms]
  4. A test fails once in twenty runs. Describe your procedure from the first red build to the fix. [Flaky Tests, Retries and Quarantine]
  5. The developers refuse to add accessibility IDs. Propose a plan. [The Mobile Test Automation Checklist]
  6. How would you test a screen that opens a payment provider's WebView? [Hybrid Apps and WebViews]

Part 4: Review questions with short answers

Python Flash cards: answer first, then reveal

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Part 5: Mini challenges

  1. Add a --platform option to a pytest conftest.py and make two screen objects work on both platforms.
  2. Write a script that reads devices.json, assigns unique ports per worker, and prints the capabilities for each.
  3. Parse a JUnit XML file and print the five slowest tests.
  4. Audit a page source (copy one from the Inspector) and list clickable elements with no ID and no description.
  5. Design a smoke suite of five tests that would give you confidence in a release in under ten minutes.

Where to go next

Keep the course material beside a real app. Install Appium and the Android emulator, write the login suite from the first project against any open-source app, add a second platform, run the suite in CI, then try a cloud trial. Each step teaches problems no tutorial can predict.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which two capabilities must differ for two parallel sessions on the same Android host?

    Each parallel session needs its own device and its own UiAutomator2 system port.
  2. 2. The best response to a test that fails once in twenty runs is to:

    Find the cause; retries only hide it.
  3. 3. Which statement about driver.contexts is correct?

    It returns names such as NATIVE_APP and WEBVIEW_...
  4. 4. Why test the permission-denied path?

    Auto-granting hides failures that real users can trigger.

Summary

  • You practiced capability validation, waiting, failure analysis, bug spotting and suite design.
  • Most mistakes come from a few families: capabilities, waits, session leaks, fragile locators and shared state.
  • Real skill comes from running a suite on a real app, on two platforms, in CI.

Next: back to the Appium track overview