3

I have such environment Appium + iOS Simulator + Java. I have to test such case:

  1. I click on button in App
  2. My app is going to website
  3. I need to check the URL

I searched this problem and realized that webdriver for iOS is not switching between app and browser that is why I can't use commonly used code:

driver.getCurrentUrl();

So, I decided to check If the URL which I've just clicked is correct or not. But I don't know how to get this URL. May be somebody has experience in that issue?

I decided to clarify: I am into iOS native App pressing on button and after this I'm redirecting to the safari on the some URL. Can I have some possibilities to know this URL without safari (in the moment when I'm still inside App).

S.Manko
  • 151
  • 1
  • 2
  • 15

1 Answers1

0

Although getCurrentUrl is working for Android when the web browser opens as in a different context than the "Native APP" context, it is not implemented for iOS XCUITest when Safari opens as "Native APP" context.

In the case of iOS(Safari) you can use the following:

wait until safari app opens(wait till next Statement is True):

appiumDriver.queryAppState("com.apple.mobilesafari").toString().equals("RUNNING_IN_FOREGROUND")

Then click on the URL Bar and get the TextValue of it:

MobileElement urlToolBar = appiumDriver.findElement(By.xpath("//XCUIElementTypeOther[@name='URL']"));
urlToolBar.click();
appiumDriverWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//XCUIElementTypeTextField[@name='URL']")));
MobileElement urlTextFied = appiumDriver.findElement(By.xpath("//XCUIElementTypeTextField[@name='URL']"));
String desiredUrl = urlTextFied.getText();

In case Page Factory is used within the project then replace findElement with @iOSXCUITFindBy

miyaman
  • 1
  • 1