Working with web-apps

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.

Web apps on Android

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:

Web apps on Android

Perform the following steps to load the native browser on an emulator and then type data in the Google search box:

  1. Update the desired capabilities in the setup() method to launch the native browser:
    caps.setCapability("avd","AVD_Nexus_4");// Mention the created AVD name
    caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Browser");
  2. Now, we need to navigate to https://www.google.com using the following command:
    driver.get("https://www.google.com"); //On web apps we need to navigate the url to test the desired website
  3. We need to find the searchBox element; in this section, we are going to find an element by name:
    WebElement searchBox=driver.findElement(By.name("q"));
  4. Now, we need type in the search box:
    searchBox.sendKeys("Appium for mobile automation");
  5. Run your script using TestNG; it should look like the following block of code:
    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.

Web apps on iOS

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:

Web apps on iOS
  1. Perform the following steps to load the browser on the simulator and then type data in the Google search boxUpdate the desired capabilities in the setup() method to launch the Chrome browser:
    caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari");
  2. Now, we need to navigate to https://www.google.com using the following command:
    driver.get("https://www.google.com");
  3. We need to find a searchBox element; in this section, we are going to find an element by name:
    WebElement searchBox=driver.findElement(By.name("q"));
  4. Type the following in the search box:
    searchBox.sendKeys("Appium for mobile automation");
  5. Run your script using TestNG; it should look like the following block of code:
    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();
    }
    }
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.230.164