Web apps can be run on any device or platform. The only requirement for running them is a web browser and an Internet connection; the best part is that you don't need to install the app on the device. Web apps are generally designed with cross-browser compatibility.
We will take the example of the Gmail login page. In this section, we are going to take a look at how to load the Chrome browser on a real device and then type in invalid credentials and click on the Sign in button that is shown in the following screenshot:
Let's start with the following steps to automate the web apps:
caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
driver.get("https://www.gmail.com");
command.username
box element (we can take a reference from Chapter 4, Finding Elements with Different Locators, to find an element); in this section, we are going to find an element by name
:WebElement username=driver.findElement(By.name("Email"));
username.sendKeys("test");
password
box element; in this section, we are going to find an element by name
:WebElement password=driver.findElement(By.name("Passwd"));
password.sendKeys("test");
name
:WebElement signIn=driver.findElement(By.name("signIn"));
signIn.click();
public class TestAppIication { AndroidDriver driver; @BeforeClass public void setUp() throws MalformedURLException { DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome"); caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4"); caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); caps.setCapability(MobileCapabilityType.DEVICE_NAME,"Moto X"); 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.gmail.com"); WebElement username=driver.findElement(By.name("Email")); username.sendKeys("test"); WebElement password=driver.findElement(By.name("Passwd")); password.sendKeys("test"); WebElement signIn=driver.findElement(By.name("signIn")); signIn.click(); } @AfterClass public void tearDown(){ driver.quit(); } }
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 browser on a real iOS device and then type data in the Google search box shown in the following screenshot:
Let's start with the following steps to automate web apps:
setup()
method to launch the Safari browser:caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari");
driver.get("https://www.google.com");
command.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");
ios_webkit_debug_proxy -c 2e5n6f615z66e98c1d07d22ee09658130d345443:27753 –d
Replace 2e5n6f615z66e98c1d07d22ee09658130d345443
with the attached device's UDID and make sure that the port is set to 27753.
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, "iPad"); caps.setCapability("udid","Real Device Identifier"); 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(); } }
3.144.111.49