How to handle mouse wheel events in Robot Framework using Browser Library? - mouseevent

I am looking for a way to test mouse wheel events in Robot framework using the Browser library. I was looking in the documentation but couldn't find any way.

I have the below approach of using JavaScript to test/run mouse events. There might be other ways to achieve mouse wheels events using Selenium or other methods. There is no straightforward method to test mouse wheel events in Robot Framework using Browser Library. Here is a solution which I got after Researching:
Emit Mouse Wheel Events
[Documentation] Takes some parameter and emits the wheel event to
simulate mouse event
[Arguments] ${CtrlKey} ${ShiftKey} ${deltaY}
${ElementToApplyMouseEvents} = Get Element //valid-selector
Log ${ElementToApplyMouseEvents}
Execute Javascript (elem) => { let event = new WheelEvent(“wheel”, {deltaX:
-400,deltaY:
${deltaY},view: window,bubbles:true,ctrlKey: ${CtrlKey}, shiftKey: ${ShiftKey}});
elem.dispatchEvent(event); } ${ElementToApplyMouseEvents}
Sleep 1s
Take Screenshot EMBED fullPage=true

Related

Proper way to close dialogs in Flutter tests

Flutter's WidgetTester has a pageBack() method for popping the route stack. When I open a page as a fullscreen dialog using MaterialPageRoute's fullscreenDialog property, the pageBack() method does not work ("One back button expected on screen"). I can't find an alternative method for the job.
What is the standard way to cancel/close a dialog in a Flutter test?
I am able to close the dialog as follows:
await tester.tap(find.byIcon(Icons.close));
But then I could have instead done a pageBack() as follows:
await tester.tap(find.byIcon(Icons.arrow_back));
Why have the pageBack() method but no equivalent for closing a dialog?
I have not yet written my Cupertino UI yet. Will that test need to look for a different icon?
See also a similar problem I had with selecting the overflow menu.
UPDATE: Maybe pageBack() emulates pressing the system back button, not the back arrow? In that case, there would be no need to emulate the behavior on iOS, and I would have to find the back button by icon to emulate pressing it, anyway.
You can have a dialog that contains a button with a text 'X', which pops the dialog.
This button, you can find with
await tester.tap(find.text('X'));
and don't forget to pump to go through with the tap
await tester.pumpAndSettle();
Have a look at the full code sample the flutter team is using to test dialogs: source code
I think finding by Icons.close seems reasonable. I did similarly in my app. Another option could be assuming the x,y of the button in the navigation bar and just tapping at that location on the screen.
I faced a similar problem earlier and I found the following solution that worked fine for my case.
Navigator.of(context, rootNavigator: true).pop('dialog')
Or you can write like,
Navigator.of(context).pop();
Navigator.pop(context);
You can check the brief documentation on Flutter Navigation and Routing here.
Hope, this would work. Have a great day.

Selenium WebDriver: is it possible to test WebExtension that inject code to the current page?

I found articles about opening browser extension as a page - but my extension inject JS to the current page - and extension can not inject code to chrome* pages. My only choice is SikuliX? Also with SikuliX I can test the badge of my button. I think that with SikuliX I simulate real user behaviour - such tests about UI interactions looks like more robust for me. Also nice to test CSS correctness.
I tried to setup a hotkey for my extension:
But
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'I') (Python) or driver.findElement(By.tagName("body")).sendKeys(Keys.CONTROL + "I") (Java)
do nothing, but I can press Ctrl+I and I see popup-UI opened.
UPDATE: I tried to use pyautogui for mouse clicking - but even with opened extension popup UI driver.window_handles does not include it :(
You can configure webdriver to load your extension in to the browser while launching as well. Once your extension in loaded , it can inject required code that i am assuming makes some changes to html such as adding / removing some html elements or applying some styles which can be then tested using Selenium. You can also execute javascript using selenium.
Sikuli framework is based on image recognition and then simulating user interactions on it using mouse and keyboard . Your test cases might break under these scenarios :
Change in resolution which may even result in layout changes
Change in theme of the application resulting in color changes of ui-elements
It will require focus ,etc.
Currently, I test my extension by comparing expected and actual screenshots, using Selenium web driver, pyautogui (for interactions with extension) and opencv2 (for computer vision), see more at https://www.pyimagesearch.com/2014/09/15/python-compare-two-images/

Recognizing element in an Hybrid App - Android

I am new to Android testing. I am currently trying to automate a scenario. I have attached the snapshot of the app screen:
Scenario:
I need to click on "Clock In".
A screen slides from the bottom as shown in the snapshot.
I need to select an item as shown by the arrow.
The developer is saying that it is a Hybrid app. A lot of confusion here for me as I am able to click on "Clock In", but I am not able to select "DL 380 Memory Upgrade".
Doubts:
How to find whether "DL 380 Memory Upgrade" is in Webview/Native?
If it is an element in the webview, how to locate it? I located "CLOCK IN" as below:
#AndroidFindBy(xpath = "//android.view.View[#resource-id='tab-t0-0']")
private AndroidElement clockInTabBtn;
If its an element in WebView, then its web and you won't find anything in web while searching by resource-id - its native attribute only.
I would recommend to use chrome dev tools for debugging hybrid application.
You can read official docs for setup.
Basically you need:
connect device
go to chrome://inspect/#devices in chrome browser
check phone & allow usb debugging if popup appears
check what webViews chrome spotted and click inspect for the one you need
And now you search for elements and their locators the same way you did in Selenum/Web automation
Don't forget to switch context to WebView in your appium test before you actually searching inside webView.
Good luck!
You can check available view using context and can switch to it using follows code:
Set<string> contextNames = driver.getContextHandles();
for (String contextName : contextNames)
{
System.out.println(contextNames);
//To swicth to webview
if (contextName.contains("WEBVIEW")){
driver.context(contextName);
}
}
Please refer this thread for similar issue: https://github.com/appium/appium/issues/7243

How to automate native "Search" button in Appium Java

driver.findElementById("SearchField").sendKeys("bacon");
After sending keys the Native Keyboard opens automatically on IOS.
How can i automate Tap on native keyboard "Search"?
Appium + Java + Selenium + Eclipse
If you are using java-client 3.1.0, you can use this:
((AndroidDriver) driver).sendKeyEvent(AndroidKeyCode.ENTER);
Assuming you are automating a native mobile application. then you can easily click on the search button.
driver.findElement(By.Xpath("xpath of search icon")).click();
If you are automating web application then you need to change your context to native like below.
STEPS
Get the current context handles
Save the current context Context to Native
Change the Context to Native
Click on the search button
change the context to default
CODE
driver.getContextHandles();
String currentContext = driver.getContext();
driver.context("NATIVE_APP");
driver.findElement(By.Xpath("xpath of search icon")).click();
driver.context(currentContext);
Not sure if this would be helpful for you since it's been half a year but I did have a similar problem. If I was going to search with "Bruno Mars" in the search field, I would just have appium type in "Bruno Mars\n" and the newline would automatically trigger the search button. However, recently my devices weren't responding to the new line anymore. I winded up downgrading the google keyboard to 4.1.x and I was able to use new line method again. The problem was that the devices had auto updated to to version 5.x. So downgrading the keyboard solved the issue for me.

How to play & pause video using Selenium?

Can anyone help me with how to automate play/pause video present on the web page using Selenium..
Thanks in advance...
This is extremely dependent on the browser and the player handling the video. You'll need to use the JavaScript executor, most likely.
I was discussing this last night with a pal and he came up with the following example using the Python variant of Webdriver for a demo video from html5demos.com:
driver = webdriver.Firefox()
driver.get("http://html5demos.com/video")
driver.execute_script('document.getElementsByTagName("video")[0].play()')
You can also "pause" where the "play" is used.
There's a larger question here: what are you actually trying to verify? That simply playing and pausing doesn't throw any errors? Make sure you know what you're validating and that it makes sense to actually work to automate the video test versus just leaving that particular use case to a manual test. (Though you could use the above script to get you to that point!)
** EDIT: Check out this bit of Python code (not mine) which exposes a "Paused" property. Now you could at least validate video loads, starts, and can be stopped. I'm still skeptical of the use of this sort of test, but at least it's a start.
By Using FlashObjectwebDriver !
Now what is FlashObjectWebDriver ?
FlashObjectWebDriver is an interface under Webdriver Library.
FlashObjectWebDriver has a Method called : callFlashObject
callFlashObject method can be over loaded using arguments ie.
callFlashObject(“Play”) : For Playing the Flash
callFlashObject(“Pause”) : For Pausing the Flash
callFlashObject(“Previous”) : For playing previous Flash video
callFlashObject(“next”) : For playing next Flash video
callFlashObject(“SetVariable”, “/:Message) : For displaying the message .
Implementation :
FlashObjectWebDriver flashApp = new FlashObjectWebDriver(driver, "myFlashMovie");
// Pass the URL of video
driver.get("http://demo.guru99.com/flash-testing.html");
Thread.sleep(5000);
flashApp.callFlashObject("Play");
Thread.sleep(5000);
flashApp.callFlashObject("StopPlay");
Thread.sleep(5000);
flashApp.callFlashObject("SetVariable","/:message","Flash testing using selenium Webdriver");
System.out.println(flashApp.callFlashObject("GetVariable","/:message"));