Saturday, August 31, 2019

How to develop Headless mobile test cases in a development project | Mobile Automation

How to develop Headless mobile test cases in a development project? | Mobile Automation



How to create Headless script when your app is in development

if your app is in development and not ready to start scripting and you don’t have application to develop test cases, then what usually Automation test engineer need to do is :
  1. Based on the mocks or wireframes develop head less scripts (Head Less scripts are containing the steps and actions but they will not have element locators)
  2. Once application or feature is ready for testing, first find out the locators for your script from developed app and add those into your Headless script
  3. now you can execute your script and no need to wait till application is completely developed
How to create head less scripts ?

if you have requirement for Login page, usually in all the projects you will be having mocks or wire-frames that will give how many buttons, text boxes and links will be available in that page.

So based on Login page mock, you can make your scripts steps like below:


  1. navigate to login page
  2. enter user name
  3. enter password
  4. click on Login button
  5. User should be navigated to dashboard page
Now for the above steps you can create below Headless script:


public void verifyLoginFunctionality()
  {
         driver.findElement(By.xpath("Login Page Link")).click();
         driver.findElementByXPath("user name field xpath").click();
      driver.findElementByXPath("password field xpath").click();
      driver.findElementByXPath("Login Button field xpath").click();
     
     Boolean dashboard= driver.findElementByXPath("Dashboard xpath").isDisplayed();
     Assert.assertTrue(dashboard);
     
  }

In the above script, once your application is ready you just need to update the locators and you can execute the scripts.

Complete Headless script code:


package practise;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import junit.framework.Assert;

public class HeadLessScriptExample {
      
       static AndroidDriver<MobileElement> driver;
      
       @BeforeTest
        public void setup() throws InterruptedException, MalformedURLException {
            
           DesiredCapabilities cap=new DesiredCapabilities();
           cap.setCapability("deviceName", "emulator-5554");
           cap.setCapability("udid", "emulator-5554");
           cap.setCapability("appPackage", "your app package name");
           cap.setCapability("appActivity", "your app activity name");
           cap.setCapability("platformName", "Android");
           cap.setCapability("platformVersion", "9.0");
           driver=new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), cap);
           driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
           Thread.sleep(5000);
          
}
      

  @Test
  public void verifyLoginFunctionality()
  {
         driver.findElement(By.xpath("Login Page Link")).click();
         driver.findElementByXPath("user name field xpath").click();
      driver.findElementByXPath("password field xpath").click();
      driver.findElementByXPath("Login Button field xpath").click();
     
     Boolean dashboard= driver.findElementByXPath("Dashboard xpath").isDisplayed();
     Assert.assertTrue(dashboard);
     
  }
                   

}


No comments:

Post a Comment

If any suggestions or issue, please provide