1

I'm trying to automate Android testing using Appium. What I want to do is like:

My Test Suite:

Test case 1:
Starting from Activity A
Do something

Test case 2:
Starting from Activity A
Do something

The problem is that if you go to another Activity while performing test case 1, you need to somehow navigate back to the first Activity.

At first I've tried manually going back.

My Test Suite:

Test case 1:
Starting from Activity A
Do something (<- this takes you to Activity B)
Navigate back to Activity A

Test case 2:
Starting from Activity A
Do something

But if the case fails on the step Do something, Navigate back to Activity A won't execute. What would be the best practice?

  1. Separate cases into suites?
  2. Navigate back to Activity A on afterEach block?
  3. Or anything better?

This won't make any significant differences, but I'm using Appium + Jest + WebdriverIO.

1 Answer 1

1

Make your tests independent of each other.

Jest has the concept of beforeEach and afterEach functions. Use these to start and quit your Appium session for each test.

When the app opens for each test it will be in the same place, and you can work forward from there.

It adds a little overhead to each test, but it will let you avoid major headaches trying to write 'recovery' code in case something unexpected happens and a test doesn't end where you need to.

If you plan to use a device farm (e.g. Browserstack) at any point, there may be issues with running your tests on the same session, too. It probably won't record session videos correctly (one long video instead of individual test cases) and you will probably hit a session timeout if your (single session) test goes over 15-30 minutes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.