dygraph chart validation via ui automation - automation

I want to validate dygraph charts using UI automation. Values are displayed on mouse hover.
Value gets displayed under span tag on mouse hover. I want to fetch these values from protractor ui test so i can validate it against a source of truth

http://www.protractortest.org/#/api?view=ElementFinder.prototype.evaluate this is what you need. But you may need help of developers to ask what variable you need to evaluate. But try this first and see what comes back
let $elem = element(by.css('dygraph'))
let data = await $elem.evaluate('data')
console.log(data)

Related

How to indicate certain events to Selenium tests?

I'm relatively new to Selenium testing. I have a React SPA I want to create Selenium tests for. I can work with locators and such, but I don't know how I can make the test wait for certain events.
I.e.: The test opens a page where I have a list that is loaded via an API. I need the test to wait until the content is loaded. How can I indicate this to the test? I may be able to check the spinner and wait until it disappears, but there could be situations when the spinner doesn't even appear. Besides, I need to handle events when there are no elements in the list or when there is a communication issue with the API. I really don't want to rely on user messages and spinners.
Should I create an DOM element which is invisible to the user and fill it with the event result so the test can read it? This also doesn't seem a good solution for me.

Can TestCafe follow a sequence through multiple pages?

I am very new to TestCafe, (but excited by what I see) so this might be a dumb mistake.
All the examples of TestCafe that I have found, depend on a single URL.
However, I want to test a very familiar sequence:
user makes some choices in page X and clicks submit,
user is shown multiple matching records in page Y, and clicks something in one result,
user sees a detail page Z, with full information for one record
When I try this in TestCafe, my test terminates when control leaves X. It never sees Y.
So, in the last lines of my test, after it submits page X
await t
.click(submitButton);
.. if I look for values which should be in page Y,
await t
.expect(Selector('#back-to-home-page').innerText)
.contains ('Back to Page X');
the Selector cannot find them. It only finds things still in page X.
(I have testcafe v 6.14, but this is not version-specific).
Thank you.
I'm not sure if I understand your question precisely, is page Y a different page that opens? (eg. you click on submit and page Y opens in a new tab / window)
See this for that: https://devexpress.github.io/testcafe/documentation/guides/advanced-guides/multiple-browser-windows.html
Also, judging by the last sample you provided, it might be the case that the element doesn't load fast enough?
Try something like:
await t
.expect(Selector('#back-to-home-page').innerText).contains('Back to Page X', {timeout: 20000})
See if the element is actually there before testcafe expects it.
Thank you for that idea Liviu.
My case is only in a single window, not multiple windows or tabs. Page X and Y are different URLS on the same domain: a form then a search results page. A completely typical flow.
I tried your good suggestion, but it did not work and now I know why.
For reasons unknown so far, the Page X submit button remains disabled even after TestCafe completes the required inputs. It is visible but greyed out. With human entry, this does not happen, only with TestCafe data entry. Some piece of JQuery validation is not getting triggered.
As newbie, before this, I did not know for sure if Testcafe could follow from page X to Page Y in any case, which would be an awful limitation. But I now have proved to myself that works, when I use TestCafe on other sites.
I can't solve the JQuery on my test site, and it is too detailed to post here. But I am happy to close the question.
Thank you guys.

How to identify element for notifications that disappear within few seconds?

I've a test case where after creation of an item, notification is shown, but that notification disappear s within 2-3 seconds.
I want to identify the element for that notification, but when I try to inspect element for that in firebug, it's HTML snippet disappears very quickly since notification itself disappears. Hence I couldn't identify element for it and finding it very difficult to automate.
Can anyone suggest how to deal with such situation?
Since you say "I've a test case", I'm thinking you are testing an application of yours. The plainest way to get around your problem is to know your application. Even if a third-party library is providing the notification code, you can read the doc to see if you can increase the delay or you can read the source code to figure out how it creates the element and where.
If the above fails, then if you can get together a sequence of operations in Selenium that triggers a notification, you should be able to get a serialization of body quickly enough that you can then examine at your leisure. Using Selenium for Python, it would go:
print driver.execute_script("return document.body.outerHTML;")
I would run the code above with redirection to save the output of the print statement to a file that I'd then examine at my leisure. You could make it narrower if you wish by getting the outerHTML of a descendant of body. I like to have a good bit of context so that I know where exactly the element is being created. I've used libraries and configurations that create such notifications as children of body, and some that put them as children of other elements.
Open the previous page before the notification
Press "Ctrl+Shift+c", Navigate to "sources" tab
Do the manual step to generate the notification, which is going to hide in few seconds
Press "F8". Page load scripts will be paused
Then inspect the element as usual and fetch the xpath at your convenience
You can use the below JAVA code to wait for 20 seconds till any element with text 'your notification' appears in the page:
try{
WebDriverWait wait = new WebDriverWait(driver,20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[contains(text(),'Your notification here')]")));
}catch(Throwable e){
System.err.println("Error while waiting for the notification to appear: "+ e.getMessage());
}

Selenium cursor focus on field

I'm creating tests (in Firefox) for a web app.
Depending on what field the cursor is over, a different help screen will appear. But when creating tests for those help screens, i cant get Selenium to focus on the particular field i want.
I've tried using fireEvent, click, select, and type in order to get the focus to stay on the field i require in order to load that particular help screen but i've had no luck.
Does anyone have ideas on how this can be solved. Or how i can work around it?
You can use selenium2 AdvancedUserInteractions API:
Actions builder = new Actions(driver);
builder.moveToElement(someElement).build().perform();
if my understanding of your question is correct, you wanted to display different help screens for differnt elements,
o.k here it is, if the message of the screen is displayed as a tool tip and the styling is taken care by mouseover event
selenium.mouseOver(locator) and then [ Thread.sleep(1000) ] and then use
selenium.mouseOut(locator)
try with this.if you don't get it and if my understanding of your question is wrong please post it.
you must investigate how that screen is being is displayed. and try to post all that code

Selenium: Loop Through Each <option> in Drop Down List

I'm using Selenium to ease my testing burden and I have about 1,000 different drop down list combinations (spread across multiple pages and drop down lists) that need to be tested. Basically, what I would like to do is select each <option> inside of a <select>, click the Submit button, select an item (first, second, third, etc.) in the drop down list on the resulting page, click submit, and then go back and select the next item, in sequence. Each time, it should assert that a certain value (related to the drop down list value selected) is present on the final page. Does anybody know if this kind of logic is possible in Selenium?
I'm having a hard time explaining this, so hopefully this pseudo code clears things up
foreach option in select
select option
submit form
foreach option in select
select option
submit form
assert that page contains text that matches selected values
Edit: I have selected values from the drop down list while the recorder is playing, but it seems like the recorder isn't picking up the selected drop down list values. Nor have I been able to figure out how to perform the operation for each <option> in a <select>.
The first question I have is whether or not it's even possible. If it is, could somebody please point me in the right direction to get me started?
Edit 2: I'm not opposed to using another web automated testing utility. If anybody has any recommendations for a free alternative, please feel free to make that recommendation.
What language are using Selenium in? If you're just using Selenium by writing HTML, I'd recommend switching to a programming language and using Selenium RC -- bindings are available for a wide variety of languages, such as Java and Python. In Java, I believe the following would do what you want:
void test(Selenium browser, String startPageUrl,
String firstFormLocator, String firstSelectLocator,
String secondFormLocator, String secondSelectLocator) {
browser.open(startPageUrl);
for (String option : browser.getSelectOptions(firstSelectLocator)) {
browser.open(startPageUrl);
browser.select(firstSelectLocator, "label=" + option);
browser.submit(firstFormLocator); // Or click the submit button
for (String subOption : browser.getSelectOptions(secondSelectLocator) {
browser.open(startPageUrl);
browser.select(firstSelectLocator, "label=" + option);
browser.submit(firstFormLocator); // Or click the submit button
browser.select(secondSelectLocator, "label=" + subOption);
browser.submit(secondFormLocator); // Or click the submit button
// Do your assertions
}
}
}
The code isn't exactly readable, so it might be worth some time abstracting the page away slightly using the Page Object pattern. This also helps make the code more maintainable, for instance when you change the ID of an element, you only need to change it in the page object rather than every test.
Also bear in mind that doing this 1000 times isn't going to be quick. It might be worth seeing if you do similar testing just below the web interface to allow quicker feedback from tests, and then test the web interface is using the lower layer correctly. Also, do you really need 1000 tests? It seems that there's some redundancy in testing here -- is the 1000th test going to fail if the last 999 have passed?