How to write a code to click on forgot password link which is sent to mail Id switch back to native app in ios

I am trying to automate forgot password scenario which goes like this

  1. Open forgot password page in test app and give registered mail Id
  2. Open mail app in iOS and search for particular mail
  3. click on forgot password link which opens in safari
  4. Enter new password
  5. Relaunch test app without resetting

As of now i can send test app to background using runAppInBackground(10), But how to open mail app without closing test app session in ios ?

open email in another thread.
you can do this in ordinary selenium with any browser available on PC where script running and click on forgot password link (or use new password given - depending of how it is working).
or you can do this using API of email service e.g. Gmail has :slight_smile:

Thanks @Aleksei for the quick response. Is there any way i can open Mail Application in the device after sending test app to background?

on real device i think no. on simulator should be possible.

Instead of mail app, you can open email in safari

There is nothing in email standards indicating that the email will show up right away. On a real mail server you could be looking at minutes, hours or even days before the email arrives from a mail server.

For this reason I usually have a mail server setup for test purposes. Look for something like “SMTP server with web interface”. The full set up is to have the forgot password service setup to point at my test SMTP mail server. So when you send a ‘forgot password’ it goes to the backend service. The backend service should be configurable. It will be configured to send the email to the user via my SMTP mail server (rather than a real SMTP mail server). I then configure the test mail server to leave the email in a queue. If the test mail server has a web interface I can get the email (and the link) via the mail server’s web interface. I can then launch a new Appium session using the web browser on the device with the link from the email.

The test would be:

  • Open Appium instance with the app you are testing
  • Go to Forgot Password page
  • Enter an email (can be anything because we are using a fake email server, including [email protected])
  • Open the SMTP mail server web interface with a second Appium instance (or I could use the desktop browser)
  • Find the forgot password email (it should be there almost instantly)
  • Click the forgot password link in the email
  • Reset your password
  • Close second Appium instance
  • Using first Appium instance, go to Login page and use new password

This tends to be more reliable than using a real mail server. Also the fake SMTP mail servers are REALLY easy to setup. You can have everything running locally.


@darrell888 thanks you so much for reply.

How to create one more appium session when one session is already running ? if i close previous session using driver.close()/ driver.quit(), It will be reset on creating once again.

Can you please help me with the code

@Hi Vikram, This is what exactly i was looking for. Can you please share sample code if it is working for you.

Please follow the steps as per thread I mentioned. It’s quite straight forward. I don’t have any open source project code to share for now.

The variable driver is just a convention. I can declare an instance of driver using:

IOSDriver driver = new IOSDriver(url, capabilities);
// your code here

But I can also use:

IOSDriver foofoohaha = new IOSDriver(url, capabilities);
// your code here

If you want to create two instances of Appium driver you can do:

IOSDriver driver = new IOSDriver(url, capabilities);
IOSDriver driver2 = new IOSDriver(url, capabilities);
// use driver to go to the forgot password page and do the necessary steps
// use driver2 to open the web interface to the SMTP mail server
// use driver2 to reset your password
// use driver for the rest of the test