Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package firstProject;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.AutomationName;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import io.appium.java_client.service.local.flags.GeneralServerFlag;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.io.File;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
public class IOSDriverDefined {
AppiumDriverLocalService server = null;
public static void main(String[] args) throws MalformedURLException, InterruptedException{
IOSDriverDefined instanceCreated = new IOSDriverDefined();
AppiumDriver <MobileElement> driver = instanceCreated.setupDesiredCapForIOS();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElementByXPath("//XCUIElementTypeButton[@name = 'Allow']").click();
System.out.println(driver.getStatus().toString());
instanceCreated.getServer().stop();
System.out.println("Server has stopped");
}
public IOSDriver <MobileElement> setupDesiredCapForIOS() throws MalformedURLException {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "SE_SecondGenPractice");
desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "IOS");
desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);
desiredCapabilities.setCapability(MobileCapabilityType.APP, "//Users/fida20/Programming/JavaProjects/MavenProjects/MobileAutomationProjects/firstAppiumProject/src/main/resources/testApp.app.zip");
desiredCapabilities.setCapability("noReset", true); //ensures that the application does not reinstall every time reset is called
desiredCapabilities.setCapability("udid", "4C8E1FF0-BCFB-44BB-86A1-5095D5F6C05A");
desiredCapabilities.setCapability("platformVersion", "14.4");
desiredCapabilities.setCapability("useNewWDA", true);
desiredCapabilities.setCapability("showXcodeLog", true);
HashMap<String, String> environment = new HashMap();
environment.put("PATH", "/usr/local/bin:" + System.getenv("PATH"));
AppiumDriverLocalService server = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.withEnvironment(environment)
.usingDriverExecutable(new File("//opt/homebrew/Cellar/node/15.8.0/bin/node"))
.withAppiumJS(new File("//Users/sagolGoru20/.npm-packages/lib/node_modules/appium/build/lib/main.js"))
.usingAnyFreePort()
.withArgument(GeneralServerFlag.SESSION_OVERRIDE)
.withLogFile(new File("//Users/fida20/Programming/JavaProjects/MavenProjects/MobileAutomationProjects/firstAppiumProject/appiumLog.txt"))
);
server.start();
// IOSDriver <MobileElement> iosDriver = new IOSDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities);
IOSDriver <MobileElement> iosDriver = new IOSDriver<MobileElement>(server.getUrl(), desiredCapabilities);
return iosDriver;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment