I'm trying to find a way for me to close all tabs of chrome after performing certain tasks with Appium using Java, for example on Android. Is there a way I can do that? All tabs keep growing and growing and that causes the tests to crash.
One possible solution is to clear the application data using ADB:
adb shell pm clear com.android.chrome
You may do this as a precondition for your tests, for example somewhere in #BeforeClass or #BeforeSuite if you use TestNG. The side effect is that you have to accept terms and conditions upon chrome opening and click the No thanks button on the Sign-in to Chrome View. But this is not a big deal.
Pros: clean Chrome browser without any tabs and cache on every test run
Cons: some Chrome initialization is required every time (~5..10 seconds to perform)
You can also try another approach as written here: https://developers.perfectomobile.com/display/TT/How+To%3A+Close+Tabs+in+Google+Chrome
Create a function (inside your app #BeforeSuite or #BeforeClass) that will simulate touch events of a mobile user that press a button to close all chrome tabs.
Related
I am running an appium script on an Android emulator from via Android studio device manager. I want to see the device on the screen when my appium test is running on it, so I manually click the device icon in the taskbar to bring the device to the foreground so it can be in focus. No issues with that.
Now, sometimes I forget to bring the device to the foreground before running the script, so whilst the script is running, I quickly bring it to focus manually. Is there a way programmatically bring the running device to the foreground?
I easily achieve this with selenium webdriver to bring a browser tab into focus by doing this:
String window = driver.getWindowHandle();
((JavascriptExecutor) driver).executeScript("alert('Test')");
driver.switchTo().alert().accept();
driver.switchTo().window(window);
This is not working in appium. Is there a way to achieve a similar result with appium? Or perhaps, Is there some settings in Android studio to automatically bring the running device into focus?
It's a maven project and I am running the test on macOS.
My guess would be to create a gradle run configuration that would use some kind of terminal script that would focus the emulator window by name? Like running wmctrl on Linux.
You would probably have to create a focussed question here if you would get stuck on any of these steps though. As I don't even know what OS you are on.
Again I request and need your help.
I'm testing a graphical element, for that, I'm taking screen shots of the graph. One is the expectation and the other one is the current graphic in the chrome browser.
We are running this test in different windows.
My issue is : the windows can have another resolution or another chrome version installed. If there is a diff configuration, then, my two screen shots will be differents because I'm comparing them pixel by pixel, and, my test will fail.
My question is : there is a way to force or emulate chrome to have the same text size, version, ...
Thanks
I've been using chrome driver (with selenium wedriver), so far it never caused any issue, now for some requirement it has to be in foreground with focus on it.
How can I make sure it is in the foreground?
Just immediately after navigating to your test URL, Maximize and Switch To the new window. It will come in the fore ground (provided you don't interfere with your mouse ;)
browser.navigate().to(test_URL);
browser.manage().window().maximize();
browser.switchTo().window(browser.getWindowHandle());
Finally I found the answer from one of the post, it worked for me, URL:
Bring the Firefox Browser to Front using selenium Java (Mac OSX)
My goal is to open a new window running a flash app from an url (http://curvefever.com/CF_Preloader.swf), and be able to interact with it with java, and do things like take screenshots of the content, and invoke keypresses.
while I could achieve this by opening the flash app in a browser and monitor the browser with selenium (and using an awt robot to take screenshots), I am looking for a better method because I want to avoid the extra lag brought with running the browser, but also because other windows might obstruct the screenshots when the browser window is in the background.
I think Selenium is still a good choice for manipulating the Flash application.
You can use the WebDriver's built in screenshot ability, which only captures the browser, so you won't have to worry about other windows obstructing the one you want to capture.
Take a screenshot with Selenium WebDriver
I've an issue with my IE browser when running selenium WebDriver java scripts. For a while it will run in front of the screen, at some point of time it's going behind the screen and what ever other windows opened in the system comes to front. This is affecting the flow of the scripts run mostly. Can any one suggest a solution. Thanks !!!
There was a known issue with the IE window being pushed to the bottom of the Z-order (to the background) when doing certain operations with the IE driver. Among these were calling WebElement.click() and selecting elements in a <select> element. These issues were corrected in 2.26.0.9 of the IEDriverServer.exe. Updating both your language bindings and your IEDriverServer.exe to the latest version (2.28, at the time of this writing) will likely solve your issue.
I've solved this issue to some extend by using window.focus() method. Where ever IE window goes behind the screen, we must use it to bring it back infront of the screen. Here's the code snippet ((JavascriptExecutor)driver).executeScript("window.focus()");
Thanks :)