Reputation: 647
My app contains multiple activities. The flow is:
SplashScreen -> Activity 1 -> Activity 2 -> Activity 3 -> ?
Activity 1 has a button that leads to Activity 2.
Activity 2 has an editText (must fill) and then a button that leads to Activity 3.
Activity 3 has buttons that lead to the rest of the app
What my code currently does is:
//Define WebDriver
dr = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
dr.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//Activity 1
dr.findElement(By.id("com.package.name:id/btnLoginWithEmail")).click();
//Activity2
dr.findElement(By.id("com.package.name:id/emailField")).clear();
dr.findElement(By.id("com.package.name:id/emailField")).sendKeys("[email protected]");
dr.findElement(By.id("com.package.name:id/btnVerifyEmail")).click();
To my understanding, Appium will always try to find the element in the current running activity, even if it's the SplashScreen. If it will fail, it will try again and again. My questions are:
Essentially, the question I'm asking is: What is the correct way to test a certain flow of your app in case there is more than one activity?
I tried to find sample codes, but I couldn't find one for this specific scenario.
Upvotes: 3
Views: 2270
Reputation: 1205
You should write test cases in same way as real user interact with your application. During simulation if need scrolling then use Appium scroll function to get exact element of activity.
Upvotes: 0
Reputation: 1780
Well, an answer for your first question is to use driver.currentActivity()
We should never bother about the current activity of an application. Better write code which will simply check element is available or not in the current context.
Alright if your requirement is to first verify activity then look for an element then use String currentActivity=driver.currentActivity()
Upvotes: 1