Appium iOS: Testing Mobile Forms (Signup page) with Appium

Last updated on:


package main.java.engine.appImpl.pageobjects;

import java.util.Random;
import main.java.AppDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;


public class SignUpPage extends AppDriver {
	
	 @FindBy(xpath = "//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATextField[1]")
	 public WebElement username;
	
	@FindBy(xpath = "//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATextField[2]")
	private WebElement email;
	
	@FindBy(xpath = "//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIASecureTextField[1]")
	private WebElement password;
	
	
	@FindBy(xpath = "//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATextField[3]")
	private WebElement gender;
	
	@FindBy(xpath = "//UIAApplication[1]/UIAWindow[2]/UIAPicker[1]/UIAPickerWheel[1]")
	private WebElement genderPicker;
	
	@FindBy(className = "UIAPickerWheel")
	private WebElement picker;
	
	@FindBy(xpath = "//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATextField[4]")
	private WebElement dob;
	
	
	@FindBy(xpath = "//UIAApplication[1]/UIAWindow[2]/UIAPicker[1]/UIAPickerWheel[1]")
	private WebElement monthPicker;
	
	
	@FindBy(xpath = "//UIAApplication[1]/UIAWindow[2]/UIAPicker[1]/UIAPickerWheel[2]")
	private WebElement dayPicker;
	
	@FindBy(xpath = "//UIAApplication[1]/UIAWindow[2]/UIAPicker[1]/UIAPickerWheel[3]")
	private WebElement yearPicker;
	
	@FindBy(name = "Join")
	private WebElement join;
	
	public void fillUpForm() throws InterruptedException {
	
		// Generating random email, so user can get in and navigate throw the application
		 int leftLimit = 97; // letter 'a'
		    int rightLimit = 122; // letter 'z'
		    int targetStringLength = 7;
		    StringBuilder buffer = new StringBuilder(targetStringLength);
		    for (int i = 0; i < targetStringLength; i++) {
		        int randomLimitedInt = leftLimit + (int) 
		          (new Random().nextFloat() * (rightLimit - leftLimit));
		        buffer.append((char) randomLimitedInt);
		    }
		    String generatedString = buffer.toString();
		 
		    System.out.println(generatedString);
		
		// username    
		username.click();
		username.sendKeys(generatedString);
		
		
		// email
		email.sendKeys(generatedString + "@saloote.com");
		
		
		// password
		password.sendKeys("123456");
		
		// gender
		gender.click();
		genderPicker.getAttribute("values");
		System.out.println(genderPicker.getAttribute("values").toString());
		genderPicker.sendKeys("Male");
		
		// dob
		dob.click();
		
		// select month
		monthPicker.getAttribute("values");
		System.out.println(monthPicker.getAttribute("values").toString());
		monthPicker.sendKeys("March");
		
		// select day
		dayPicker.getAttribute("values");
		System.out.println(dayPicker.getAttribute("values").toString());
		dayPicker.sendKeys("29");
		
		// select year
		yearPicker.getAttribute("values");
		yearPicker.sendKeys("1987");
		
		join.click();
	}

}
View Comments

Leave a Comment

Use markdown or basic HTML and be nice.