Created
July 16, 2021 10:13
-
-
Save Jaimin180296/5ff820365d1e4e8b7261f2f0644bf4b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.appium.java_client.MobileBy; | |
import io.appium.java_client.ios.IOSDriver; | |
import io.appium.java_client.ios.IOSElement; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.support.ui.ExpectedConditions; | |
import org.openqa.selenium.support.ui.WebDriverWait; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
public class iOSTest { | |
public static void main(String[] args) throws MalformedURLException, InterruptedException { | |
DesiredCapabilities caps = new DesiredCapabilities(); | |
// Set your access credentials | |
caps.setCapability("browserstack.user", "<username>"); | |
caps.setCapability("browserstack.key", "<acesskey>"); | |
// Set URL of the application under test | |
caps.setCapability("app", "bs://444bd0308813ae0dc236f8cd461c02d3afa7901d"); | |
caps.setCapability("os_version", "13"); | |
caps.setCapability("device", "iPad Pro 12.9 2020"); | |
// Set other BrowserStack capabilities | |
caps.setCapability("project", "First Java Project"); | |
caps.setCapability("build", "Java iOS"); | |
caps.setCapability("name", "first_test"); | |
// Initialise the remote Webdriver using BrowserStack remote URL | |
// and desired capabilities defined above | |
IOSDriver<IOSElement> driver = new IOSDriver<IOSElement>( | |
new URL("http://hub-cloud.browserstack.com/wd/hub"), caps); | |
driver.getSessionId(); | |
driver.activateApp("com.apple.mobilesafari"); | |
Thread.sleep(2000); | |
driver.findElementByAccessibilityId("URL").click(); | |
Thread.sleep(3000); | |
driver.findElementByAccessibilityId("URL").sendKeys("https://www.maxmind.com/en/locate-my-ip-address"); | |
Thread.sleep(3000); | |
driver.findElementByAccessibilityId("Go").click(); | |
Thread.sleep(5000); | |
driver.navigate().back(); | |
driver.activateApp("com.browserstack.Sample-iOS"); | |
// Test case for the BrowserStack sample iOS app. | |
// If you have uploaded your app, update the test case here. | |
IOSElement textButton = (IOSElement) new WebDriverWait(driver, 30).until( | |
ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Button"))); | |
textButton.click(); | |
IOSElement textInput = (IOSElement) new WebDriverWait(driver, 30).until( | |
ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Input"))); | |
textInput.sendKeys("[email protected]"); | |
Thread.sleep(5000); | |
textInput.clear(); | |
IOSElement textInput1 = (IOSElement) new WebDriverWait(driver, 30).until( | |
ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Input"))); | |
textInput.sendKeys("[email protected]"); | |
Thread.sleep(5000); | |
IOSElement textInput2 = (IOSElement) new WebDriverWait(driver, 30).until( | |
ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Input"))); | |
textInput.sendKeys("[email protected]"); | |
Thread.sleep(5000); | |
IOSElement textOutput = (IOSElement) new WebDriverWait(driver, 30).until( | |
ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Output"))); | |
if (textOutput != null && textOutput.getText().equals("[email protected]")) | |
assert (true); | |
else | |
assert (false); | |
// Invoke driver.quit() after the test is done to indicate that the test is completed. | |
driver.quit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment