Appium + iOS + Java how to get URL that I've just clicked? - java

I have such environment Appium + iOS Simulator + Java. I have to test such case:
I click on button in App
My app is going to website
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).

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

Related

outsystems iFrame issue

I'm using outsystems and I am trying to get the app to run in their browser but something about iFrame popped up. How do I disable iFrame so that the app can run in the browser?
"Your app requires native access to a Local Storage database that is not available in your browser while using an iframe.
Please test your app in your mobile device or use Google Chrome"screenshot
Try this:
On Safari Options go to Advanced > Experimental Features and at the end turn off the option that say Disable Web SQL.

Android WebView: How do I allow deep links?

When I click on a link within my WebView, it behaves as expected - it opens the link within the WebView.
However, if an app can handle that link, I would like to open that app instead. For example, if I tap on a Twitter link, I would like it to open Twitter, else open in-app.
This is how Google Chrome on Android behaves. This is also how WKWebView, the iOS equivalent of WebView, also behaves.
How would I go about implementing that? I have attempted to implement the solutions here but now my app always wants to open the system browser.
Deep Links as handled by OS itself. You just need to implement it properly. For example, in Android if you want to open the following url
http://twitter.com/intent/tweet?text=YOUR_TEXT
it will open the twitter app if the app is installed in your phone. Otherwise it will be opened in your browser.
But in case of iOS you have to specify the URL Scheme for opening in another app. Check the following url
twitter://post?message=YOUR_MSG
So when implementing this SO answer, you should also consider about the URL Schemes.
You should also keep in mind that webview in the application are implemented so that you don't have to open the browser app and no urls are exposed. If you want to open another app, you must consider opening the url in browser from your app so that OS can handle the rest.

APPIUM ANDROID Hybrid App: Not able to get driver context as 'WEBVIEW' when navigating to the web view from native in Hybrid app

I need to automate web view in Hybrid app. Native part automation is going fine. After clicking on one of the buttons in the native view, the app is further navigated to the Chrome browser and opens the web view. Now, the problem is that I am not able to get 'WEBVIEW' in the String Set using the driver.getContextHandles(). I only get value as 'NATIVEAPP' even after navigating to the webview. Kindly let me know where I am going wrong or there's any other approach for the same.
Tried the driver.getContextHandles() to get all contexts and then ran 'for loop' to set the driver to WEBVIEW context to perform the further actions on webview.
//Below code is after clicking on the button on native view which
//navigate to the web view in the chrome browser
Set<String> contextNames = driver.getContextHandles();
System.out.println(contextNames);
for (String conName : contextNames) {
System.out.println(conName);
if (conName.contains("WEBVIEW"))
{
driver.context(conName);
}
}
//clicking action in the webview in browser
driver.findElement(By.xpath(XYZ)).click();
I expect driver.getContextHandles() value as: NATIVEAPP,WEBVIEW. But I only get NATIVEAPP as output.
In order for you to be able to do any type of debugging of webview inside apps. The need to enable the web view debugging option through this key being added to the app's config: setWebContentsDebuggingEnabled and setting it's value to true.

WebPage works if opened manualy. Returns "Window language could not be determined" if opened via Selenium

I am dealing with a small problem. I am working on automating few tasks in a web application,i can open the webpage,enter the login,click login,BUT then it starts to act strange. If i click on the login manualy it logs in without a problem.
But if i try to do it via selenium (JAVA jdk1.7.0_75,selenium-java-2.53.1,running on IEDriverServer_Win32_3.4.0) the page opens with error An error has occured.
java.lang.NullPointerException. and with "Window language could not be determined "
The page is on the intranet. I guess the application has a problem with the Webdriver (everything works if i try to automate the task using the VBS).
Dont you know any "workaround" for that?
(I can use only IE,because chrome no longer supports NPAPI so the application does not work in chrome)
InternetExplorerDriver driver = new InternetExplorerDriver();
driver.get("*the webpage*");
driver.findElementByName("userid").sendKeys("*login*");
driver.findElementByName("password").clear();
driver.findElementByName("password").sendKeys("*password*");
driver.findElementByName("ctr").sendKeys("*number*");
driver.findElementByName("menuType").click();
driver.findElementByLinkText("OK").click();
I think the problem is somewhere in the settings,because as i mentioned,if o open the browser manualy and login,it works,no errors and i get into the app.
But the webdriver "browser" has somehow different settings (i think) so it does not work. Problem is,that we have restricted access to the settings of browser,so i cant do much about that.
Thank you very much for any suggestions/answers/tips!!
Kind Regards,
Jerry Woodburn

How to interact with different android browser (get url)

I'm searching for a way to interact with different android browsers.
My intention is to get the URL of the website that is opened by the browser.
My app should run in background and give an alert when a specific url is opened, for now this is for testing and to learn more about android.
Is there any way to tell the browser to pass the url-string to my app everytime a new url is entered?
I've already got the idea to implement a local proxyserver wich checks all http-requests for a specific url, but is there a better way?
aditionally this should work with every browser not just the standard one but also eg. firefox or dolphin.
I already searched the last few days but couldn't find an answer....
Yes, you can do this! Check out http://seleniumhq.org/ for how to automate a web browser.

Categories