I've been asked to use Selenium to write some tests for a website. Several of the pages have graphs on them that are generated by the "chart.js" library. The tests require me to:
Read the size of some of the data values in the chart
Click on certain bars on the chart.
Hover over certain bars and validate the tool tips
The trouble is the chart is implemented as a single HTML canvas element, so there is no DOM for the details of the chart that selenium can manipulate.
You won't be able to access the chart directly using Selenium because there is no DOM, as you noted. There may be a way to access chart data using JavascriptExecutor to run JS commands. I'm not familiar with chart.js but I have written automation against CANVAS elements. I got with dev and talked to them about what I needed access to and they gave me pointers on methods, etc. that I could call to get what I needed. I use the page object model so I ended up writing some Java functions that wrapped around the JS code that accessed the CANVAS.
Related
I have a collection of utilities and modeled pages that our TestCafe tests rely on. I'm working on a POC to see if we could utilize that code from within the TestCafe Studio. I assume there is a template somewhere that is used to help generate the JS code that results from pressing the Convert to JavaScript button, but I may be wrong. If it exists, I'd like to know how I can add some imports to the top of it.
Alternatively, if there is a way to run a script before the tests run, then maybe I can import my utilities and pages and add them to the context.
TestCafe Studio does not allow modifying a template to generate JS code using the Convert to JavaScript button.
However, you still can use your utilities and scripts inside the TestCafe Studio test code. Please refer to the following help topic for more details: Custom Scripts.
I'm writing automated UI tests using Robot Framework with python. I'm testing a Polymer application that uses the shadow dom Robot's standard libraries don't seem to be able to locate elements in the shadow dom using xpath.
I've been sorting through selenium's repo/overflow/internets and polymer's repo/overflow/internets and haven't found the intersection of a solution for using robot with python (the selenium workaround isn't that graceful either). I was hoping someone had run into this issue with this specific framework that might be willing to share a solution (or note that there's not one).
Test Case
Wait Until Page Contains Element xpath=(//html/body/some-root-shadow-dom-element/input)
This of course results in an error because the shadow dom is not put into the main document of the DOM tree.
Open the browser console and type this into the console:
dom:document.querySelector("apply-widget").shadowRoot.querySelectorAll("div)
Make sure to hit enter after so it will be ran.
I'm trying to use OpenTest with web applications created with IBM EGL using the Dojo toolkit. The issue with dojo is that it dynamically generates id's every time so they cannot be used as a locator. In addition many elements do not have an xpath so that can't be used either.
It seems like this is a common issue when I search for "dojo" and "selenium" but I haven't found any solutions yet.
Other testing tools have "explicit" support for specific frameworks (e.g. like dojo) so I assume it's technically feasible.
Here is an excerpt from a website where this same question was asked and OpenTest supports building out macros that do just what this indvidual was able to do with .NET code. Please reference the blockquote below as well as the source
I use Selenium to Test my web application which is built by dojo/dijit
and asp.net MVC, so far it works fine.
I've faced the same issues with yours before. My way is "don't think
about dojo widgets" when writing steps interacting with them. Treat
them as normal complex html elements. You need to browse your dom tree
on the client after dojo parse your widgets, locate the real dom
element which dijit's value node or interactive part corresponding to
and do thing (Click, SendKey or GetId in your case) to it.
It is also good to wrap some common actions to widgets into Helpers
which can be reused in your project.
Below is a simple .NET example I use to test whether a button exist in
a dGrid, I just use css selector to find the cell, hope it helps:
[Then("I can delete it at row '(.*)'")]
public void Then_I_can_delete_it_at_row(int rowIndex)
{
var nthRow = Browser.FindElementsChecked(By.CssSelector(".dgrid-content .dgrid-row-table")).ElementAt(rowIndex - 1);
var deleteBtnsInRow = nthRow.FindElementsChecked(By.XPath(".//span[text() = 'Delete']"));
Assert.AreEqual(1, deleteBtnsInRow.Count);
}
Can we automate graphs generated using canvas tag for test automation in selenium using python?I want to extract the data points plotted on the graph.
You can using ocular ,if your graph is not dynamically changing for every second.
Through selenium we cannot automate graphs.
You can refer to http://www.testautomationguru.com/selenium-webdriver-how-to-automate-charts-and-graphs-validation/
you can embed ocular along with selenium code
I am new to test automation and I need help of experts who can help me in proceeding with the current difficulties.
Currently there is a web browser application which is tested manually based on the test cases in an excel.
There is also an automation framework also which uses Selenium and uses WebDriver and runs on Google Chrome.
The test cases(in excel) used for manual are taken up and another set of test cases(in excel) are written which is nothing but the div elements and the action which the framework should do like click or find which the framework will understand.
1.First I need to manually find out each div id for all the elements and put it in excel which the framework understands.How can I avoid this?
2.Also a new version of the application has come in which all the div id for the elements differ.Hence its pain to note the div id again and put them in excel.
How can I write the test cases only once for each case even if the div changes?
Please help.
Follow a design pattern, e.g. Page Objects
If ids will be changed try to use css and xpath selectors that do not stick to ids. The main idea is to specify such selectors that allow tests to find elements on the page using knowledge by their parents, tag names, other attributes that won't change (class and so on).