How to handle Micro Popup in Webdriver.io browser - webdriver-io

When starting a website, I find it difficult to click Block button on Microphone popup because I can't query this popup (and also with block btn)
How can I handle this problem with Webdriver.io in browser?
enter image description here

One option is to use chrome command line switches. You can find the list here.
The one you are looking for is use-fake-device-for-media-stream. You can set this in your config file so that every time the chrome is launched, it won't show this popup since it is already set to a fake device.

Related

How to get rid of google pop-ups while testing and navigation google url?

Every time I navigate to google through Selenium, I encounter this popup. I can't click on the search bar. Is there a way to close permanently this popup without using any JS alert method etc.?
I tried some extensions but it didn't work
Click the Lock button (🔒) on the top-left of the search box
Click on 'Cookies'
Make sure you're on 'allowed' and find anything on the lines of google.com
Click Block, Done and refresh the page
Additionally, you may want to try it first without the web-driver 'Chrome is being controlled by automated test software' mode, so open Google Chrome you way you usually would.

Selenium test closing window dialog

I'm using Selenium with Robot Framework to write my GUI tests. One of the tests is verifying if, when the user clicks on the Close window/tab button (outside of the webpage), it triggers the alert box before exiting.
I've tried the keywords "Close window" and "Close browser", but both of them ignore the event and close the window. I also tried to close the window with javacript window.close();, but it doesn't work for windows that aren't opened with window.open(); - it is a security measure. I'm using Selenium Grid with different browsers on Linux and Windows, but everytime is failing. Is there a possibility to check this with selenium or I have to use other tools like AutoIT that automate any GUI, not only the browser?
After five days of searching for a solution, I didn't find one that tries to close the page/tab/window and triggers that alert confirmation box.
Instead, I found a workaround that is similar to that and also triggers the necessary alert which is captured by Selenium: click on a link, reopen the same page or go to another one. Like this:
Go To https://stackoverflow.com/
Handle Alert action=DISMISS
I put here action=DISMISS to simply continue with my test on the same page, but if there is need you can change it to something else.

Is the Selenium click() recognized as human or automation?

My scenario which produces the question goes something like below:
I enter a webpage via normal means, next I press on a button, to start a HTML5 application on this webpage, this application is inside an iFrame. On application start I'm being prompted to either turn the sound on or off. At this point there are two possible outcomes:
1. When I answer this prompt manually, new buttons appear in the application window, as expected.
2. When I answer this prompt through automation via Appium, new buttons do not appear.
Now to the question:
To answer the prompt I use the click() method from Selenium. Is it possible that this click() is not considered to be executed by a human and therefore doesn't trigger necessary things? And since I don't have access to the source of the application can I force the Selenium click() to look exactly like a human click?
Here is the code I use to execute the mentioned click:
//Application loading up, hence the sleep
Thread.sleep(5000);
AppiumTestBase.getDriver().switchTo().frame("e_iframe");
Thread.sleep(5000);
WebElement soundOff = AppiumTestBase.getDriver().findElement(By.id("soundOff"));
AppiumTestBase.getStandardWaitTime().until(elementToBeClickable(soundOff));
soundOff.click();
The program is able to find and switch in to the iFrame, there are no cross-origin issues either. The AppiumTestBase is just there for initializing the driver, setup capabilities etc. I also tried clicking the element via Actions and JavaScript, but there was no change in behavior.
In C# a workaround I've found to actually take control of the mouse and move it/click with it is to use "Microsoft.VisualStudio.TestTools.UITesting" for the Keyboard/Mouse libraries. From there, you can tell it "Mouse.Click(new Point(X, Y));"and it will move your mouse to that location and click.
Sample Code:
using Microsoft.VisualStudio.TestTools.UITesting;
var soundOff = AppiumTestBase.getDriver().findElement(By.id("soundOff"));
Mouse.Click(new Point(soundOff.Bounds.X, soundOff.Bounds.Y));

Have selenium interact with safari "store password" popup?

I have a selenium test that tests the login of a site through a browser instance available on a selenium-grid. This works fine when using a firefox browser instance but when using safari the test cannot get through the entire test because safari pops up a window with the question "Would you like me to save this password".
It doesn't seem to appear as a window_handle nor as an alert. How can I have selenium dismiss this safari popup and continue its test?
You can't. WebDriver cannot interact with browser and/or OS specific dialogs.
You probably have two choices:
Save/dismiss the password manually the first time you run through the test, then reuse the profile every time.
Press Enter or Esc programatically via your programming language. You didn't specify which one you're using, so here's a Java example:
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ESCAPE);
robot.keyRelease(KeyEvent.VK_ESCAPE);
It's a hack, but it's reliable and it's what I've been doing to overcome similar issues.
Try this code, it uses JavaScript to change the password to text, and this stops the pop-up:
driver.executeScript("Array.prototype.slice.call(document.getElementsByTagName('input')).forEach(function(e){e.type=e.type=='password'?'text':e.type;});");
Alternatively, you can selectively disable password capture for specific domains. You can also disable password capture altogether by clearing the auto-fill option for username/password.

How to get Selenium to respond to Chrome's site init popup?

I am trying out Selenium with ChromeDriver to automate some audio/video tests.
But When I fireup the Chrome Browser with my app it asks me the question http:... wants to use your camera and microphone Allow Deny Options I want to click on Allow and proceed with the scripting on the site. But I cannot proceed without selecting Allow. Unfortunately Chrome pops up this question in a sort of Non-DOM format that I am not able to do a driver.findElement the obvious way and respond with a "click" on the "Allow" option. Has anyone of you encountered this situation and what is the best way to deal with this ?
Cheers !
-- Brian
See this answer (print dialog) or this answer ("Run As..." dialog).
Different dialogs, but the reason (in short, WebDriver can't handle these dialogs) and possible solutions are absolutely the same:
The Robot class, it allows you to "press" programatically anything on the keyboard (or clicking blindly) and therefore getting rid of the dialog by, say, pressing Enter or Esc. However, as told above, any advanced interaction is dependant on OS / language / printer.
// press Escape programatically - the print dialog must have focus, obviously
Robot r = new Robot();
r.keyPress(KeyEvent.VK_ESCAPE);
r.keyRelease(KeyEvent.VK_ESCAPE);
You can, of course, type anything via this class, too.
AutoIt. It's a Windows program useful for handling any system-level automation. Same dependancy as above.
Note that (as far as I know) you can't really check whether the dialog showed up or not, so you won't be able to catch a possible error if it runs on a computer without a camera...
If you're using a ChromeDriver you can get to any 'native' popups using
Alert popup = webDriver.switchTo().alert();
// here you can examine the text within the alert using popup.getText();
popup.accept();