Appium - How To Handle Alert Dialog Of Android App

Alert dialog Is mutual chemical cistron of whatsoever android software app then you lot must know how to handgrip android app warning In appium or how to click on OK push of android app warning In appium automation test . You tin top away warning when you lot click push or check the banking concern tally box to top away confirmation. Alert dialog contains OK as well as Cancel buttons as well as you lot tin click on OK or cancel button. Right now, There Is non whatsoever Implementation of alert In AndroidDriver. So nosotros postulate to uncovering simply about choice to handle warning In android appium software automation test. We tin process warning same equally other elements In our android appium software automation test.

App To Use In Test
We volition role API Demos android software app In this test. You can download API Demos software app from THIS PAGE. Install API Demos app In your android device.

Aim To Achieve In Appium Android Test
We Wants to click on OK or Cancel push of warning In this appium android software automation exam equally shown In bellow Image.



Manually you lot tin navigate to inward a higher house warning dialog hide from Open API Demos app -> Tap on App -> Tap on Alert Dialogs -> Tap on OK Cancel dialog amongst a message button.

Create And Run Appium Android Test To Handle Alert
Create novel file HandleAlert.java under Android parcel of your projection as well as re-create glue bellow given software automation exam script In It.

HandleAlert.java
package Android;  import io.appium.java_client.android.AndroidDriver;  import java.net.URL; import java.util.concurrent.TimeUnit;  import org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  populace degree HandleAlert {  AndroidDriver driver;    @BeforeTest  populace void setUp() throws Exception {   DesiredCapabilities capabilities = novel DesiredCapabilities();   capabilities.setCapability("deviceName", "ZX1B32FFXF");   capabilities.setCapability("browserName", "Android");   capabilities.setCapability("platformVersion", "4.4.2");   capabilities.setCapability("platformName", "Android");   capabilities.setCapability("appPackage", "io.appium.android.apis");   capabilities.setCapability("appActivity","io.appium.android.apis.ApiDemos");   driver = novel AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);   driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);  }   @Test  populace void okOnAlert() {   // Scroll till chemical cistron which contains "App" text.   driver.scrollTo("App");   // Click on App.   driver.findElement(By.name("App")).click();   // Scroll till chemical cistron which contains "Alert Dialogs" text.   driver.scrollTo("Alert Dialogs");   // Click on Alert Dialogs.   driver.findElement(By.name("Alert Dialogs")).click();   // Click on "OK Cancel dialog amongst a message" button.   driver.findElement(By.name("OK Cancel dialog amongst a message")).click();   // Get the text from warning dialog.   String trial = driver.findElementById("android:id/alertTitle").getText();   System.out.println("Alert text Is -> " + result);   // Click on OK push of warning dialog.   driver.findElement(By.name("OK")).click();   // Click on Cancel push of warning dialog.   // driver.findElement(By.name("Cancel")).click();  }   @AfterTest  populace void End() {   driver.quit();  } }

Android Appium Test Description
Comments are provided amongst every tilt In inward a higher house android appium exam script. Selenium has Alert degree to handle alerts of spider web application. But It still Alert degree Is non Implemented amongst AndroidDriver then nosotros tin non role It In our test. Here nosotros convey located Alert text container as well as OK push manually. Also you lot tin click on Cancel push of warning using concluding statement.

This Is the means to handgrip warning dialog In android appium test.

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post