Testing mobile onboarding coach marks with Appium

By: Slav Kurochkin

Nowadays, displaying onboarding screens to first-time users has become a common practice in mobile apps. The purpose of these onboarding screens — also referred to as walkthroughs — is to introduce the app and demonstrate what it does.
(Germaine Satia at Smashing magazine)

There is some circumstances when you will need apply some logic, such as "if else", "try catch" etc, it is helping us to predict human behaviour and be more flexible and dynamic in test automation. Today I faced one problem, our application having coach marks, user have an ability disable coach marks, so I were trying to implement detection isElementPresented on the screen or no. In order to run tests without braking code and continue to perform test I were need catch exception (catch(org.openqa.selenium.NoSuchElementException e)). Since coach mark is basically an image it is quite complicated to discard it, I were using javascript Executer so test can perform taping on specific coordinate on the screen

package test.java.pageobjects.modulesAbstraction;


import java.util.HashMap;
import main.java.com.app.webdriver.manager.AppDriver;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

/**
 * @author slavkurochkin
 *
 */

public class CoachMarksPageObject extends AppDriver {
	
	@FindBy(xpath = "//*[contains(@name,'1-568h@2x.png')]")
    private WebElement coachMark;
 
	 @FindBy(xpath = "//UIAButton[1]")
	 private WebElement checkBox;
 
	 @FindBy(xpath = "//UIAImage[1]")
	 private WebElement coachMarkTapbleArea;
	
	@SuppressWarnings("serial")
	public void coachMarksTest() throws InterruptedException {
		
		try{
			JavascriptExecutor js = (JavascriptExecutor) driver;
			coachMark.isEnabled();
			checkBox.click();
			Thread.sleep(1000);
			js.executeScript("mobile: tap", new HashMap<String, Double>() {{ put("tapCount", 1.0); put("touchCount", 1.0); put("duration", 0.5); put("x", 104.0); put("y", 295.0); }});
			
			}
			catch(org.openqa.selenium.NoSuchElementException e){
				System.out.print("Coach mark was not on the screen");
			}
	}
}
View Comments

Leave a Comment

Use markdown or basic HTML and be nice.