Skip to main content

Mobile Web Browser Automation using Appium

Appium supports the automation of mobile web applications. Web apps are not really the applications but they are really websites which changes its layout as per the mobile device display and feels more like mobile native application. Being a website they run on a browser which can be Android, Safari, Chrome, Opera Mini or any other mobile browser. 

Make sure Appium has been installed along with all the dependencies. If not follow the instruction mentioned here.

Script for mobile web app automation

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

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.Test;

public class AppiumMobileAppTest {

 WebDriver driver;

 @Test
 public void androidBrowserTest() throws MalformedURLException {

  // capabilities of the android driver
 DesiredCapabilities capibilities = new DesiredCapabilities();
 capibilities.setBrowserName("Browser"); // use chrome for Chrome browser
 capibilities.setCapability("deviceName", "Nexus5"); //update device name
 capibilities.setCapability("platformVersion", "5.0.1"); // update platform version
 capibilities.setCapability("platformName", "Android");

 driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),
   capibilities);

 driver.get("http://appium.io/");
 driver.findElement(By.xpath("html/body/nav[1]/div/div[1]/button")).click();
 WebDriverWait wait = new WebDriverWait(driver, 10);
 WebElement element = wait
   .until(ExpectedConditions.visibilityOfElementLocated(By
   .xpath(".//*[@id='bs-example-navbar-collapse-1']/ul/li[7]/a")));

 element.click();

 Assert.assertTrue(driver.findElement(By.tagName("h1")).getText()
   .equalsIgnoreCase("Tutorial"),
   "Tutorial page hearer not loaded");

 driver.findElement(By.xpath(".//*[@id='readmeMarkdown']/div/a[2]"))
   .click();
 Assert.assertTrue(driver.getTitle().contains("Tutorial"),
   "Android Tutorial page not loaded");
  driver.quit();
 }
}

Popular posts from this blog

Appium setup on WIndows

Appium is an open source test automation framework for use with native, hybrid and mobile web apps.
It drives iOS and Android apps using the WebDriver protocol. Below are the step by step instructions to run Appium on windows machine for Android automation.

1. InstallJDK (7+) on your machine and set JAVA_HOME in environment variables.
Setting JAVA_HOME:   Right click My Computer and select Properties.
  a) On the Advanced tab, select Environment Variables, and then add JAVA_HOME pointing to    where the JDK is located, for example, C:\Program Files\Java\jdk1.7.0_79
  b) Updated the Path variable(Be careful with this as it might corrupt your OS)   Edit Path variable and append with ; followed by %JAVA_HOME%\bin
2. Download android sdk from here ->SDK Tools Only -> android-sdk_<version>-windows.zip   Extract it on a location and set up ANDROID_HOME in environment variables
Setting ANDROID_HOME:   Right click My Computer and select Properties.
  a) On the Advanced tab, select En…

Broken Link Checker using Java & Selenium

We often come across the requirement to validate the links (i.e. Checking Broken links) in the web pages. Performing this task manually is tedious as there might be high number of links in your web page. Generally to validated it we depend on the third party websites where there might be confidentiality issues. Below is the code snippet which can be used locally & quickly to check the links without compromising on confidentially.

import com.jayway.restassured.RestAssured; import com.jayway.restassured.config.RedirectConfig; import com.jayway.restassured.config.SSLConfig; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; import java.util.List; public class LinkChecker { WebDriver driver = null; public void validateLinksInPage() { List<WebElement> anchorTagsList = driver.findElements(By.ta…