Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automating android emulator and browser using Appium script

Performing automation test on android emulator using appium. Browser in emulator is not opening when it is automated via code. I have copied my code below kindly look into it and help me out. Thanks in advance

package report;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;  

import javax.swing.JOptionPane;

import org.openqa.selenium.By;  
import org.openqa.selenium.WebDriver;  
import org.openqa.selenium.WebElement;  
import org.openqa.selenium.firefox.FirefoxDriver;  
import org.openqa.selenium.firefox.FirefoxProfile;  
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeTest;  
import org.testng.annotations.Test;  


public class emulator {
WebDriver driver;

public void setUp() throws MalformedURLException 
{
DesiredCapabilities capabilities= new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME,"browser");
capabilities.setCapability(CapabilityType.VERSION,"4.4");
capabilities.setCapability(CapabilityType.PLATFORM,"windows");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("devices","Android");
capabilities.setCapability("avd","nexus");
capabilities.setCapability("deviceName","");
capabilities.setCapability("appPackage", "com.android.browser");
capabilities.setCapability("appActivity",    "com.android.browser.BrowserActivity");
driver=new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}



public void cal(){
driver.get("http://www.google.com");

}
public static void main(String[] args) throws MalformedURLException
{
emulator a=new emulator();
a.setUp();
a.cal();           
}
}
like image 475
bcrajkumar Avatar asked Sep 14 '15 10:09

bcrajkumar


People also ask

Will Appium work for mobile browser automation?

In a nutshell, Appium is a mobile test automation framework (with a tool) that works for all: native, hybrid and mobile web apps for iOS and Android. Appium is a great choice for test automation framework as it can be used for all these different app/web types.

What mobile web browsers can I automate in the Android emulator?

Currently the only browser that can be automated in our Android emulators is the stock browser (i.e Browser). The Android stock browser is an Android flavor of 'chromium' which presumably implies that its behavior is closer to that of Google Chrome.

Does Appium support emulator?

Appium Studio allows you to test and connect to Android Emulators (x86 based emulators are preferred) or iOS Simulators. For both Android and iOS devices tablet and iPad emulators are included.


1 Answers

The lock screen will deactivate the other script of our program. So I tried open the emulator manually and disable the lock screen (Settings -> Security -> None). Then close the emulator. Now open the emulator automatically and run the script.

public void setUp(int p) throws MalformedURLException {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "browser");
    capabilities.setCapability(CapabilityType.VERSION, "");
    capabilities.setCapability(CapabilityType.PLATFORM, "windows");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("udid", "emulator-" + p);
    capabilities.setCapability("devices", "Android");
    capabilities.setCapability("avd", "Nexus7");
    capabilities.setCapability("deviceName", "");
    capabilities.setCapability("appPackage", "com.android.browser");
    capabilities.setCapability("appActivity", "com.android.browser.BrowserActivity");
    driver = new RemoteWebDriver(new URL("http://127.0.0.1:" + this.port + "/wd/hub"), 
             capabilities);
}
like image 80
bcrajkumar Avatar answered Oct 17 '22 18:10

bcrajkumar