Running an arbitrary command/program on selenium grid node - testing

Is it possible to run an arbitrary OS program on the selenium node before running tests?
Why I need such a weird thing:
In one test of the web application I need to simulate mouseover for 1 second, but the thing is - if there is a mouse pointer over the browser window then selenium webdriver doesn't keep mouseover event for long time. It's getting interrupted after several milliseconds and after that the real mouse pointer starts emitting the mouseover event.
So what I'd like to try is to run a trivial program that moves mouse cursor to the screen corner to not interfere with browser window.
Any ideas?
UPD: created a trivial app to run before starting a particular driver that would move cursor to the corner: https://github.com/zerkms/MoveCursor

Related

selenium web driver: how to enable mouse move to target elements before clicking or input values?

selenium web driver: how to enable mouse move to target elements before clicking or input values?
Mouse is not moved. How to enable it? It should be default behavior for simulating human-machine interaction.
We have so many places for entering values and clicking elements.
The Webdriver implementation does not rely on the actual mouse. It uses low-level browser implementation (through browser native automation drivers like chromedriver or geckodriver) to emulate the mouse interactions. If you take a look at the Webdriver spec, you can see that mouse interactions mention "firing events on nodes" and not actually triggering the mouse itself.
This implementation allows for tests to be run in parallel and/or in headless mode.
So if you call an API like "findSomeElement" and then "click", the result in the browser will be the same as if you had moved your mouse to the element and clicked. Except that your actual mouse pointer won't have moved an inch :)

WinAppDriver Appium not finding element visible through inspect.exe

I am programming on a WinForms application with a gui built using Visual Basic back in pre 2005. I frequently will have elements that are visible on inspect.exe, but when I am running WinAppDriver and Appium it fails to detect those elements.
This is the error I get.
OpenQA.Selenium.WebDriverException: 'An element could not be located on the page using the given search parameters.'
The error will occur even when my application is the only maximized application. It occurs when I click a button and launch another form. To make sure that it isn't because the elements haven't appeared yet, I have run the command Thread.Sleep(5000) to ensure that the form which is launched has enough time to appear.
This is the line of code attempting to click on the element.
driver.FindElementByAccessibilityId("vlblYVar").Click();
Here is a picture showing inspect.exe clearly finding the element. Any guidance would be greatly appreciated!
Turns out it just takes a significant amount of time for the elements in the window that pops up to be recognizable by winappdriver even if inspect.exe picks it up immediately.
I had to use
var element = desktopWait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.VisibilityOfAllElementsLocatedBy(ByWindowsAutomation.AccessibilityId("vlblYVar")));
desktop.FindElementByAccessibilityId("vlblYVar").Click();
Also I had to use a driver that loads the desktop UI because using my program's driver never found the element which would lead to a timeout.
I have a new issue though. When I have a combo box, the elements in that combo box are found by name with inspect.exe, but winAppDriver can never identify the elements in the combo box.

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));

Unable to locate button element

I can see the enabled button while running. I can select that button using Selenium IDE and the xpath. But when it comes to running using WebDriver it is not able to find the element.
Are you using the localhost? because sometimes if it takes some extra seconds for the Web Browser to load (for example Firefox), then when Selenium tries to do the action it doesn't find the elements obviously resulting your error.
Use the pause command, for example 5 seconds, so that the Selenium waits 5 seconds before the action is executed, giving time for the website to load.
Try the coding somewhere on this level
driver.manage().timeOuts().implicitlyWait(5,TimeUnit.SECONDS);

selenium webdriver stop working when click on different window

I'm using IE8 and webdriver.
The problem I have is every time webdriver runs I can't touch my computer. Basically the moment I click on a different window it stops working.
Because of this I can't run my code in debug mode with break point because I every time I go to Eclipse to manually execute the break point webdriver doesn't work anymore because IE8 is not selected.
With Firefox I'm able to do whatever I want but not with IE8. Is there anyway I can fix this problem with IE8?
Thank you!
The short answer is, "No, you can't fix this problem with IE at the moment." There are a number of reasons why window focus is incredibly important with the IE driver. The biggest reason is that you're using so-called "native events" when you're using the IE driver, which simulates mouse and keyboard events at the operating system level rather than just within the browser using, say, JavaScript, and the way IE processes native events is sometimes compromised if the browser window doesn't have focus. More information can be found in a presentation given at the 2012 Selenium Conference.
One approach to solving the problem would be to disable native events with the IE driver. Unfortunately, the simulated events aren't ready for normal use.