Earlier nosotros learnt how to run android automation examination inwards existent android device using appium equally described in THIS POST. So I am suggesting you lot to read It earlier running appium examination inwards AVD. Also you lot can run appium examination on android emulators (Android virtual device). We volition larn how to run starting fourth dimension appium examination inwards android emulator inwards this appium tutorial post. We volition role android emulator's attain inwards installed figurer app to attain as well as run appium automation test. Let's start it.
PREREQUISITES :
- All previous xvi steps of appium tutorial given on this LINK as well as this LINK should hold out completed without whatever error.
- Android emulator should hold out created.
- TestNG should hold out installed inwards eclipse. View THIS POST.
1. Start Appium Node Server
Start appium node server equally described inwards THIS POST.
2. Start Android Virtual Device (Emulator)
Once appium starts properly, You need to launch android virtual device equally described inwards THIS POST.
3. Get Emulator Platform Version
Also you lot need to render android emulator platform version. You tin acquire it equally described bellow.
- Unlock Android emulator screen.
- Go to Settings. You volition uncovering About Phone nether settings.
- Go to About Phone.
- It volition exhibit you lot Android version equally shown inwards bellow image. For me it is 5.1
Note downwardly android version for your emulator.
4. Verify figurer App Is Available In Emulator
We are going to run appium examination for figurer application as well as hence it should hold out at that topographic point inwards emulator. Generally figurer app volition hold out already installed inwards emulator. To banking concern jibe if it is installed or not,
- Unlock emulator.
- Verify if at that topographic point is whatever application alongside mention Calculator equally shown inwards bellow image. You tin download Android Calculator App from THIS PAGE if it is non available alongside you.
5. Get app Activity as well as Package Name
We need launcher action as well as bundle mention of figurer app. You tin role whatever of the method from THIS PAGE or THIS PAGE to acquire action as well as bundle mention of figurer app.
Activity as well as bundle mention of figurer app for me is equally bellow.
Package name : com.android.calculator2
Activity name : com.android.calculator2.Calculator
Now nosotros are attain to attain as well as run our starting fourth dimension appium examination on android emulator for figurer application. I convey prepared appium examination script equally bellow. I convey used RemoteWebDriver of selenium webdriver to launch app alongside required capabilities.
Create novel degree file nether Android package inwards eclipse alongside name SimpleEmulatorCalcTest and glue bellow given examination script inwards it.
SimpleEmulatorCalcTest.java
package Android; import java.net.URL; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.testng.annotations.Test; populace degree SimpleEmulatorCalcTest { WebDriver driver; @Test populace void setUp() throws Exception { // Created object of DesiredCapabilities class. DesiredCapabilities capabilities = novel DesiredCapabilities(); // Set android deviceName desired capability. Set it Android Emulator. capabilities.setCapability("deviceName", "Android Emulator"); // Set browserName desired capability. It's Android inwards our representative here. capabilities.setCapability("browserName", "Android"); // Set android platformVersion desired capability. Set your emulator's android version. capabilities.setCapability("platformVersion", "5.1"); // Set android platformName desired capability. It's Android inwards our representative here. capabilities.setCapability("platformName", "Android"); // Set android appPackage desired capability. It is com.android.calculator2 for figurer application. // Set your application's appPackage if you lot are using whatever other app. capabilities.setCapability("appPackage", "com.android.calculator2"); // Set android appActivity desired capability. It is com.android.calculator2.Calculator for figurer application. // Set your application's appPackage if you lot are using whatever other app. capabilities.setCapability("appActivity", "com.android.calculator2.Calculator"); // Created object of RemoteWebDriver volition all laid capabilities. // Set appium server address as well as port number inwards URL string. // It volition launch figurer app inwards emulator. driver = novel RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); // Click on CLR button. driver.findElement(By.name("del")).click(); //OR you lot tin role bellow given syntax to click on CLR/DEL button. //driver.findElements(By.className("android.view.View")).get(1).findElements(By.className("android.widget.Button")).get(0).click(); // Click on number ii button. driver.findElement(By.name("2")).click(); // Click on + button. driver.findElement(By.name("+")).click(); // Click on number v button. driver.findElement(By.name("5")).click(); // Click on = button. driver.findElement(By.name("=")).click(); // Get number from number text box of calc app. String number = driver.findElement(By.className("android.widget.EditText")).getText(); System.out.println("Number amount number is : " + result); driver.quit(); } }
Running First Appium Test In Emulator
Now nosotros are attain to run appium examination for figurer app inwards emulator.
Note : Please brand certain appium node server as well as emulator are launched as well as appium server is started past times pressing start button.
Run examination using testng as well as uncovering examination execution inwards android emulator. It will
- Open calc app inwards emulator.
- Tap on calc app's buttons inwards this sequence -> CLR, 2, +, v as well as =.
- Get number from text surface area of figurer app.
- Print number inwards eclipse console.
This agency you lot tin run appium examination inwards android emulator.