I have a Flutter (Android) app I am running test on. It uses Twilio to verify. When I run the app and it gets to the verification phase, the app is to be minimized and the SMS app should be launched to fetch the OTP sent. I set it to minimize for 2 minutes. The way it works now is that it displays the dialog of the OTP after the app is minimized, but unable to switch and close the dialog, so the driver terminates after a period of time. This is the code snippet
public class AppRunner {
AndroidDriver<MobileElement> _driver;
@Test
public void StartButton() throws Exception {
_driver.findElementByXPath("click button ot generate OTP").click();
_driver.runAppInBackground(Duration.ofSeconds(120));
String OTP = OTPVerifiy();
_driver.currentActivity();
//OTP
MobileElement otp = (MobileElement) _driver.findElementByXPath("//android.widget.EditText[@index='5' and @class='android.widget.EditText' and @Text=' Enter Otp']");
otp.sendKeys(OTP);
}
public String OTPVerifiy() {
Activity activity = new Activity("com.android.mms", "com.android.mms.ui.ConversationList");
activity.setAppWaitPackage("com.android.mms");
activity.setAppWaitActivity("com.android.mms.ui.ConversationList");
activity.setStopApp(false);
if(((AndroidDriver<MobileElement>) _driver).findElementById("com.android.mms:id/mark_as_read_btn").isDisplayed()) {
((AndroidDriver<MobileElement>) _driver).findElementById("com.android.mms:id/mark_as_read_btn").click();
}
((AndroidDriver<MobileElement>) _driver).startActivity(activity);
List<MobileElement> OTP = _driver.findElementsById("com.android.mms:id/subject");
return OTP.get(0).getText().split("-")[1].trim();
}
}
I have tested and ran successfully the OTPVerifiy
separately and it worked, but is unable to see the SMS dialog, and so, the test halts.
This is sample that I ran and worked
public String OTPVerifiy() {
Activity activity = new Activity("com.android.mms", "com.android.mms.ui.ConversationList");
activity.setAppWaitPackage("com.android.mms");
activity.setAppWaitActivity("com.android.mms.ui.ConversationList");
activity.setStopApp(false);
((AndroidDriver<MobileElement>) _driver).startActivity(activity);
List<MobileElement> OTP = _driver.findElementsById("com.android.mms:id/subject");
return OTP.get(0).getText().split("-")[1].trim();
}
Aucun commentaire:
Enregistrer un commentaire