in a continuous integration build environment when running several Selenium tests in parallel (using Firefox driver) for different applications and each tests records its screenshots after every "action" (e.g. navigating to a page, submitting a form etc.) it seems like that whichever application window pops up that one gets on the top of the z-axis and will have the focus.
So using the method getScreenshotAs() from the Selenium API to record images results in mixed up screenshots sometimes showing one application and sometimes the other application.
Recording the HTML responses with getPageSource() on the other hand seems to work correctly using the Firefox driver instance "bound" to the test.
Is there any solution how to deal with the mixed up image screenshots? Is there a possibility how to ensure that getScreenshotAs() only consideres its own Firefox driver instance? Thanks for any hints!
Peter
I don't know what flavor of selenium you are using but here is a reference to the API that looks like it would fix your problem, but I have never tested it.
http://selenium.googlecode.com/svn/trunk/docs/api/dotnet/index.html
What that link shows is the IWrapDriver which according to the documentation Gets the IWebDriver used to find this element.
So from my understanding you could set your IWebDriver in your method and then wrapit with the IWrapDriver and then use that to reference for you getScreenShotAs();
Related
Can you "get" multiple pages in parallel with chromedriver?
I am using Python, and as far as I understand selenium provides windowing API but does not allow opening a new window for a new driver.get() action. Trying to fetch a page while another is in process has proven problematic for me although I guess it might have been my wrong usage.
Currently I am opening a number of chromedriver sessions in parallel, which in turn results with X 5 times chrome processes open - This can get intimidating although it seems to work. I am just wandering now if calling driver.get(url) on an existing session (after a previous page was retrieved) might open extra tabs/windows in the "internal" chrome process and bloat memory?
You can open links in a new window using selenium by forcing a context click:
A couple suggestions:
https://stackoverflow.com/a/19152396/1387701
https://stackoverflow.com/a/45582818/1387701
You can then use the switch_to command to switch between these windows.
See more at https://www.browserstack.com/guide/how-to-switch-tabs-in-selenium-python
I am new to specflow and I am using specflow to test a website.
I have just one feature with 2 scenarios.
In the first scenario, i just invoke the browser and navigate to the home page of the application under test. I am using selenium chrome driver for this.
In the second scenario, I need to refer the instance of the chrome driver to access the objects in the web page.
However, it seems like the page is not identified. I am getting the message '..object reference not set..
I am creating the instance of the driver under under the main class as public static
Please advise on how I could refer the instance of the driver across methods which belongs to all the scenarios under the same feature
Thanks
SK
After a bit of research, I identified that the issue was related to the sequence of execution of scenarios under the feature.
I had 3 scenarios which should be executed in a sequential order. ( There might be people who argue that this is not the ideal case though). The issue was, the scenario which I was expecting to be executed as third in the sequence was getting executed as the first scenario.
By renaming the scenarios alphabetically, I was able to control the execution flow. (I believe that is the way to control execution flow in nunit) and this resolved my bug.
Thanks
SK
Is there a way to get a realtime view of what PhantomJS (or similar) is rendering?
I would like to develop my automation script while interacting with (or at least seeing a screencap of) the page it's targeted to.
No, there is no such thing. SlimerJS has the same API as PhantomJS, but runs the Gecko engine. You can see directly what is going on and run it headlessly with xvfb-run.
You will not be able to interact with it. You may want to use a screengrabber to record a video of the interaction when the tests are long and you don't want to run the test suite again if you didn't catch the problem in the test case.
The obvious way to debug PhantomJS scripts is to render many screenshots using page.render() and logging some objects to the console with
console.log(JSON.stringify(yourObj, undefined, 4));
with nice formatting.
Solution we use is an automatic screenshoting in case of exceptions, phantomJs will render the current page into a file that you can exam later .
That's for test execution phase.
When you writing the tests, just keep additional window open ("normal browser") with the application you trying to test and design the test according to it.
When the design is done, execute the test with phantomJS.
My Suggestion is to use logging alongside.
http://casperjs.org/
CasperJS is an open source navigation scripting & testing utility written in Javascript for the PhantomJS WebKit headless browser and SlimerJS (Gecko). It eases the process of defining a full navigation scenario and provides useful high-level functions, methods & syntactic sugar for doing common tasks such as:
defining & ordering browsing navigation steps
filling & submitting forms
clicking & following links
capturing screenshots of a page (or part of it)
testing remote DOM
logging events
downloading resources, including binary ones
writing functional test suites, saving results as JUnit XML
scraping Web contents
The solution to this problem is using the remote debugger:
--remote-debugger-port=9000
Using slimerjs for testing scripts with a browser is not advisable since it is based on gecko, which means the script might work on slimerjs and not on phantomjs or viceversa.
take a look at this guide for more info...
https://drupalize.me/blog/201410/using-remote-debugger-casperjs-and-phantomjs
I am using the Selenium Firefox Web Driver to run automated NUnit tests and, seemingly at random, it is not able to locate a particular button.
The function it is using is this
driver.FindElement(By.Id("createUser")).Click();
I can't figure out a pattern to why it does and doesn't work at different times. Does anyone have any ideas as to what is going on or what a possible work around might be? I am not using dynamic ids, and I have
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(15));
in place to cause it to wait up to 15 seconds for the page to fully render.
Web Consistency Testing & Selenium : is there any tool which we can integrate with selenium to perform Web consistency testing
I can do this using Selenium but its scope is limited using getallButtons, getAllFields etc. but it does not fetch all Page elements and also it only fetches only buttons or labels not every GUI element which are actually causing problems
So is there any Web consistency tool which can(prefered) or can not be integrated with selenium?
Also please suggest any others ways you know to perform this without selenium or with selenium
Mogotest is the tool designed for this testing. It is commercial though.
http://webconsistencytesting.com/
Theoretically you can obtain all page elements with Web Driver using xpath search
List<WebElement> elements = driver.findElements(By.xpath("//*"));
But processing those elements is so slow that renders this method virtually useless. Assuming you would like to invoke WebDriver's getTagName(), getLocation() and getSize() methods on every element of the web page it would take average 10 seconds (measured for a page with 190 elements which is relatively small).
If time is important for you, you need to go for difficult method which is serializing DOM to JSON or XML using javascript (you can inject javascript with Web Driver) and then parsing it in whatever language you're using for writing your Selenium tests.