top of page
Govinda Raj

Jumpstart iOS automation using Appium – Part 4

Updated: Aug 15, 2021

Example

  • Open the appium from the launchpad and start the server.

  • Make a maven project in IntelliJ with unique group Id.

  • Add this dependency in pom.xml.

Jumpstart iOS automation using Appium
  • Make a class with the name SampleTest

import io.appium.java_client.ios.IOSDriver;

import java.io.File;

import java.io.IOException;

import java.net.MalformedURLException;

import java.net.URL;

import org.apache.commons.io.FileUtils;

import org.openqa.selenium.By;

import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.remote.Augmenter;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;

public class SampleTest {

//Ios driver to operate the test
 private IOSDriver driver;

//Setting up for the device
@BeforeMethod
public void setUp() throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformName", "iOS");

//Put your device version
caps.setCapability("platformVersion", "7.1");  

//put your device name

caps.setCapability("deviceName", "iPhone Simulator");  

//Put your device bundle id

caps.setCapability("bundleid", "put your app bundle Id");

//put your app path on which you are going to test
caps.setCapability("app", "path/AppName.app"); 

driver = new IOSDriver(new URL("http://127.0.0.1:4725/wd/hub"), caps);
}

//If you want to test for logIn
@Test
public void testiOS() throws InterruptedException, IOException {
driver.findElement(By.xpath("put here username textbox xpath")).sendkeys(“put here username”);

driver.findElement(By.xpath("put here password textbox xpath")).sendkeys(“put here password”);
driver.findElement(By.name("put here logIn button identifier")).click();

//Wait for 2 seconds

Thread.sleep(2000);

//Take screenshots after login and save
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

//Put path where you want to save the screenshot
FileUtils.copyFile(scrFile, new File("path/filename.jpg"));  
}
//Now close the webdriver
@AfterMethod
public void tearDown() {
driver.quit();
}
13 views0 comments

Recent Posts

See All

コメント


bottom of page