import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.IOSElement;
import io.appium.java_client.remote.MobileBrowserType;
import org.openqa.selenium.By;
import org.openqa.selenium.ScreenOrientation;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
public class LocalMobileTest {
private String accessKey = "ACCESS_KEY";
WebDriverWait webDriverWait = null;
protected IOSDriver<IOSElement> driver = null;
DesiredCapabilities dc = new DesiredCapabilities();
@BeforeTest
public void setUp() throws MalformedURLException {
dc.setCapability("accessKey", accessKey);
dc.setCapability("testName", "Quick Start iOS Browser Demo");
dc.setCapability("deviceQuery", "@os='ios' and @category='PHONE'");
dc.setBrowserName(MobileBrowserType.SAFARI);
driver = new IOSDriver<>(new URL("https://mobiledevicecloud.t-systems-mms.eu/wd/hub"), dc);
webDriverWait = new WebDriverWait(driver, 5);
}
@Test
public void quickStartiOSBrowserDemo() {
driver.rotate(ScreenOrientation.PORTRAIT);
driver.get("https://mobiledevice.cloud/");
waitUntilElementLoaded("//*[@id='no_consent']").click();
waitUntilElementLoaded("//*[@class='navbar-toggler-icon']").click();
waitUntilElementLoaded("//*[@id='blog']").click();
waitUntilElementLoaded("//*[@id='article1']").click();
WebElement author = waitUntilElementLoaded("//*[@class='author']");
Assert.assertTrue(author.isDisplayed());
waitUntilElementLoaded("//*[@class='navbar-toggler-icon']").click();
waitUntilElementLoaded("//*[@id='link_faq']").click();
List<WebElement> faq_blocks = waitUntilElementsLoaded("//*[@class='faq_block']");
WebElement faqSearch = waitUntilElementLoaded("//*[@id='faq-search']");
Assert.assertTrue(faqSearch.isDisplayed());
Assert.assertTrue(
faq_blocks.size() > 0,
"Expected at least one faq_block element, but there are no elements with that name");
Assert.assertEquals(
faq_blocks.size(),
12,
"Expected twelve faq_block elements, but there are " + faq_blocks.size() + " elements");
faqSearch.sendKeys("automatisierte");
List<WebElement> found_faqs = waitUntilElementsLoaded("//*[@class='faq_block search-hit']");
Assert.assertTrue(
found_faqs.size() > 0,
"Expected at least one faq_block element, but there are no elements with that name");
Assert.assertEquals(
found_faqs.size(),
5,
"Expected five faq_block elements, but there are " + found_faqs.size() + " elements");
}
@AfterTest
public void tearDown() {
System.out.println("Report URL: "+ driver.getCapabilities().getCapability("reportUrl"));
driver.quit();
}
private WebElement waitUntilElementLoaded(String xpath) {
return webDriverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath)));
}
private List<WebElement> waitUntilElementsLoaded(String xpath) {
return webDriverWait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(xpath)));
}
}