The site I am creating tests for, triggers a browser request asking for the location from the mobile device.
If I shrink desktop chrome, I'm able to find the pop-up as part of chrome, but when I run in BrowserStack on an actual device, it doesn't find it.
I found a BrowserStack article specifically for this case, but I have idea how to translate into ranorex. https://www.browserstack.com/docs/autom ... on-pop-ups
Our site sets a cookie when the pop-up has been opened (whether the user allows or blocks), so that could be an option. But no idea how to do that for chrome and safari.
Any suggestions would be greatly appreciated.
Block browser device location requests
-
- Posts: 56
- Joined: Thu Oct 29, 2020 12:47 am
Re: Block browser device location requests
Hi,
The problem is, that the Selenium WD cannot (by default) handle native browser dialogs. Therefore you have to implement your own solution, using the code suggested in the link you posted. Unfortunately, I'm not using Ranorex WD integration, so I can't help you much with this. But if you search this forum, you will find a lot of WD-related examples, which may help you to understand how to work with Ranorex endpoints via code.
This post may help with obtaining actually used endpoint:
viewtopic.php?f=20&t=14194&p=55275&hili ... int#p55275
And then you need to use this information together with the sample code from your link.
The problem is, that the Selenium WD cannot (by default) handle native browser dialogs. Therefore you have to implement your own solution, using the code suggested in the link you posted. Unfortunately, I'm not using Ranorex WD integration, so I can't help you much with this. But if you search this forum, you will find a lot of WD-related examples, which may help you to understand how to work with Ranorex endpoints via code.
This post may help with obtaining actually used endpoint:
viewtopic.php?f=20&t=14194&p=55275&hili ... int#p55275
And then you need to use this information together with the sample code from your link.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
-
- Posts: 56
- Joined: Thu Oct 29, 2020 12:47 am
Re: Block browser device location requests
So that post helped me a bit, and we found a different way to handle the popups that works much better.
It works on both Android and iOS and is only a single line of code.
https://www.browserstack.com/guide/aler ... n-selenium
I'm going to utilize the same thing to be able to log in to our dev environments on mobile devices since it's the exact same type of notification.
Thanks for getting me started in the right direction odklizec!
It works on both Android and iOS and is only a single line of code.
https://www.browserstack.com/guide/aler ... n-selenium
I'm going to utilize the same thing to be able to log in to our dev environments on mobile devices since it's the exact same type of notification.
Thanks for getting me started in the right direction odklizec!
Re: Block browser device location requests
Hi Tiffin,
Could you please share your solution? I mean not just the link, but how exactly you implemented it? I'm sure it would help someone in future. Thanks.
Could you please share your solution? I mean not just the link, but how exactly you implemented it? I'm sure it would help someone in future. Thanks.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
-
- Posts: 56
- Joined: Thu Oct 29, 2020 12:47 am
Re: Block browser device location requests
Yes! I totally meant to and then forgot to actually do it.
So, need to add the following at the top of the code module:
Code: Select all
using OpenQA.Selenium;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Interactions;
Code: Select all
var webDriverEndpoint = Host.Current.TryGetAsWebDriverEndpoint();
OpenQA.Selenium.IWebDriver driver = webDriverEndpoint.WebDrivers.FirstOrDefault();
driver.SwitchTo().Alert().Dismiss();
driver.Quit();
Then it switches to the OS alert, either the location request or a login popup, and then cancels or blocks it. If you want it to allow, change Dismiss to Accept. Then it closes access to the driver so it's not constantly running.
-
- Posts: 56
- Joined: Thu Oct 29, 2020 12:47 am
Re: Block browser device location requests
An update to this, this code ONLY works for iOS. I haven't found a solution for Android.
-
- Posts: 56
- Joined: Thu Oct 29, 2020 12:47 am
Re: Block browser device location requests
Final Solutions:
Android:
Create a usercode action called SetCookies (or whatever you'd like to call it). Replace Repository Name and Application Under Test with the names from your solution:
iOS:
Setting cookies doesn't work for iOS, even after allowing cookies (it refuses to sendKeys). So the alert dismiss solution is what will work here.
Android:
Create a usercode action called SetCookies (or whatever you'd like to call it). Replace Repository Name and Application Under Test with the names from your solution:
Code: Select all
public void SetCookies()
{
// set cookies to avoid Location Request popup on mobile
var repo = (RepositoryName).Instance;
WebDocument webDocument = repo.(ApplicationUnderTest).Self;
webDocument.ExecuteScript("document.cookie = 'geocalled=true';");
webDocument.ExecuteScript("document.cookie = 'mobileGeoCalled=true';");
}
Setting cookies doesn't work for iOS, even after allowing cookies (it refuses to sendKeys). So the alert dismiss solution is what will work here.
Code: Select all
var webDriverEndpoint = Host.Current.TryGetAsWebDriverEndpoint();
OpenQA.Selenium.IWebDriver driver = webDriverEndpoint.WebDrivers.FirstOrDefault();
driver.SwitchTo().Alert().Dismiss();
Re: Block browser device location requests
Hi Tiffin,
Thanks for sharing your valuable solutions!
Thanks for sharing your valuable solutions!
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration