Seeking help on running Selenium Script in Android Studio Emulator.

42 views
Skip to first unread message

Vimal Kumar

unread,
Jun 23, 2019, 10:59:03 PM6/23/19
to Selenium Users
Hi Guys,

i just want to run the selenium script on Android Studio emulator.  Looking for some blogs/code snippet for better understanding. Kindly advise. 

Thanks 
Vimal

John Doe

unread,
Jun 24, 2019, 9:46:30 AM6/24/19
to Selenium Users
  1. Install Appium 
  2. Download ChromeDriver version which matches your Chrome browser on Android device
  3. Start Appium server and provide ChromeDriver binary path pointing to the ChromeDriver executable from step 2

foo.png


  1. Create a project
  2. Add Appium Client Library to your project
  3. Start developing code
  4. Start emulator
  5. Execute your code
Example simple script (Java) would be something like:

package webtest;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileBrowserType;
import io.appium.java_client.remote.MobileCapabilityType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;

public class AndroidWebTest {
   
ChromeOptions chromeOptions;
   
AndroidDriver driver = null;
   
DesiredCapabilities dc = new DesiredCapabilities();

   
@Before
    public void setUp() throws MalformedURLException {
       
dc.setBrowserName(MobileBrowserType.CHROME);
       
dc.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554");
       
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), dc);
   
}

   
@Test
    public void testYourAndroidApp() throws InterruptedException {
       
driver.get("https://amazon.com");
       
System.out.println(driver.getTitle());
       
if (driver.getCapabilities().getCapability("device.category").equals("TABLET")) {

           
driver.findElement(By.xpath("//*[@name='field-keywords']")).sendKeys("iPhone");
           
driver.findElement(By.xpath("//*[@text='Go']")).click();
       
} else {
           
driver.findElement(By.xpath("//*[@name='k']")).sendKeys("iPhone");
           
driver.findElement(By.xpath("//*[@value='Go']")).click();
       
}
   
}

   
@After
    public void tearDown() {
       
if (driver != null) {
           
driver.quit();
           
System.out.println("Report URL : " + driver.getCapabilities().getCapability("reportUrl"));

       
}
   
}

}


Check out Code Examples article for different languages/sample projects/more information. 

Reply all
Reply to author
Forward
0 new messages