Web apps can be run on any device or platform; the only requirement is a web browser and an Internet connection. The best part is that you don't need to install web-apps on the device. They are generally designed with cross-browser compatibility in mind.
We are going to take an example of the Google search page.
In this section, we are going to take a look at how to load the native browser on an emulator and then type data in the Google search box. Initially, we will get the native browser as shown in following screenshot:
Perform the following steps to load the native browser on an emulator and then type data in the Google search box:
setup()
method to launch the native browser:caps.setCapability("avd","AVD_Nexus_4");// Mention the created AVD name caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Browser");
driver.get("https://www.google.com"); //On web apps we need to navigate the url to test the desired website
searchBox
element; in this section, we are going to find an element by name
:WebElement searchBox=driver.findElement(By.name("q"));
searchBox.sendKeys("Appium for mobile automation");
public class TestAppIication { AndroidDriver driver; @BeforeClass public void setUp() throws MalformedURLException{ DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Browser"); caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4"); caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); caps.setCapability(MobileCapabilityType.DEVICE_NAME, "Android emulator"); caps.setCapability("avd","AVD_Nexus_4");// Mention the created AVD name driver = new AndroidDriver (new URL("http://127.0.0.1:4723/wd/hub"), caps); driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); } @Test public void testExample() { driver.get("https://www.google.com"); WebElement searchBox=driver.findElement(By.name("q")); searchBox.sendKeys("Appium for mobile automation"); } @AfterClass public void tearDown(){ driver.quit(); } }
In the next section, we will see how the same test scripts run on different platforms; we only need to change the desired capabilities, which fulfill the purpose (cross-platform testing) of using Appium.
We are going to take the example of the Google search page. In this section, we are going to take a look at how to load the browser on the simulator and then type data in the Google search box. Initially, we will get the Safari browser in simulator as shown in the following screenshot:
setup()
method to launch the Chrome browser:caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari");
driver.get("https://www.google.com");
searchBox
element; in this section, we are going to find an element by name
:WebElement searchBox=driver.findElement(By.name("q"));
searchBox.sendKeys("Appium for mobile automation");
public class TestAppIication { IOSDriver driver; @BeforeClass public void setUp() throws MalformedURLException{ DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari"); caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "8.1"); caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS"); caps.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 5"); driver = new IOSDriver (new URL("http://127.0.0.1:4723/wd/hub"), caps); driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); } @Test public void testExample(){ driver.get("https://www.google.com"); WebElement searchBox=driver.findElement(By.name("q")); searchBox.sendKeys("Appium for mobile automation"); } @AfterClass public void tearDown(){ driver.quit(); } }
44.220.184.63