Karate driver synchronization challeges - karate

Karate driven execution fails once in a while for certain elements where I use xpath. (Every three runs; one or two times it works.)
I tried the following code,
waitUntil("document.readyState == 'complete'")
click("xpath") This line fails once in a while.
The xpath is consistently working on my existing Java Selenium code.
Can another synchronization method be applied?

This will solve the problem:
* waitFor('xpath').click()
Please read this part of the documentation carefully: https://github.com/intuit/karate/tree/develop/karate-core#wait-api
Also I have found "document.readyState == 'complete'" to be unreliable. Instead try waitForUrl('partial/url').

Related

Robot Framework - capture screenshot when any keyword fails (not only selenium keywords)

I'm making automated tests cases with mix of selenium and builtin keywords in Robot Framework.
I have made the:
Register Keyword To Run On Failure Screenshot On Failure
which overwrites the default behavior to create selenium-screenshot-index.png (I needed other names). Everything works fine if the keyword failing is part of the selenium library. If not (let's say custom or builtin one) the screenshot is not taken.
Is there a way, to register the keyword to run on any failure in any keyword?
Well, depending on your actual goal solution could be quite simple or require a little bit of python programming.
Simple solution. I would say that taking one screenshot in test teardown if test case failed is enough in most of the cases.
Writing custom listener interface that would grab instance of library (Selenium, OS) and depending on keyword status would take action.

Issue with multithreading using Karate version higher than v0.9.6: http call failed after 55 milliseconds for url:

I'm running a big campaign with about 500 tests targeting the API of an orchestration tool using both a parallel and a sequential runner for some of the tests which need to be executed in sequence.
This works fine using the Karate version 0.9.6.
As soon as I upgrade the Karate version to anything higher than v0.9.6, the results of the tests in the parallel runner always consists of a significant portion of failing tests. The sequential runner does not have any issues. Also the parallel runner seems to work fine only if I set it's threadCount = 1.
If the threadCount is higher than 1, the runner seems always to start well but after some time there are quite some failed transactions without any further details like this: http call failed after 55 milliseconds for url: http://...
This is all the error log I have as there is not more than this entry for each failed test (around 40% of the full campaign).
As soon as one thread starts with an issue like that, basically all other threads follow to do the same and make their tests fail for the same reason (only with a slightly different number of milliseconds). While investigating the problem I was not able to identify a common pattern (like always starting with the same test failing, etc.).
Did anybody else face similar issues with Multithreading using a higher version than v0.9.6?
Is there a way to get more detailed logs? I use the value DEBUG in the logback-test.xml
Is there any recommendation of what to try to make it work?
Please don't hesitate in case you need more information.
I would be happy for any kind of help regarding this as I would like to benefit of the new karate-gatling facilities for Performance Testing which is only available in the latest versions of Karate.
Many Thanks for your reply!
we run 8 threads on karate 1.1.0 with no issues at all. Do you have some extra logs? So you don't get same timeout error http call failed after 55 milliseconds for url: http://... in lower version the running multithreads ?
Shot in the dark here, but do some of your scenarios have the same title? If so, try making them all unique and see if that solves the issue.
More logs will be useful. Its very little information here.
I am not sure of the exact error but I faced similar issues sometime ago but that was caused due to race conditions especially if you are trying to use variables set by java methods. Are you using Java interop in your tests? If so worth checking how these are being used. A test may be trying to execute with a variable/parameter that is still in use by other tests when running in parallel. This wouldn't be an issue in sequential.

(MS Dynamics test automation) Can not switch to iframe, frames changing automatically

I am trying to switch frames in MS Dynamics 365 system using Selenium WebDriver. I will explain one of the issues below. Here is the html element code:
element code here
Usually, i used to use id=contentIFrame0 or 1, and the frames were switching fine. The problem is, that MS Dynamics generates those iframes dynamicly, usually contains max 3 iframes(contentIFrame0, contentIFrame1, contentIFrame2), but the fact is that you never know they will be 2 or 1 on the page and why, so if you use today one of them directly - tommorow your tests will fail because of the changes.
It seems like I have to switch all the time to the last frame, but it works randomly, because sometimes there is the first one contains element and another one scripts. Other thing i tried to do, is to switch to one iframe which has attributes: style = visibility: visible(before that, i tried to print in console how many visible frames driver sees - but written all the time 0). Also, if i try to print in the console how many iframes there are on the page - the counter is 2, but I can see 3.
If there is anyone who tried to automate MS Dynamics 365 and had the same problem?
I have discribed probably all cases, maybe you will notice the logics and difference.
I am not sure if this works in your case but please give it a try.
If you know one of the elements in the frame which you are trying to switch then use the css selector or xpath
driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[title='test']")));
It very hard to test in this fashion as Microsoft doesn't guarantee that the objects being rendered will stay the same. It may be 3 frames today, but in the next version the dev team may introduce more or less, working with the DOM directly is no longer supported.
I would highly recommend the following framework for testing Dynamics: https://github.com/Microsoft/EasyRepro
It will help elevate your testing up one level, it’s introducing a level of abstraction so as to minimize the need to work with HTML directly by isolating all that low-level work in the framework code.
Here is a great post about EasyRepro: http://www.itaintboring.com/dynamics-crm/easy-repro-what-is-it/
Goodluck
This xpath finds the main pane reliably
//iframe[contains(contains(#id,'contentIFrame') and contains(#style,'visible')]
Note: not applicable to Dynamics 365 Unified Interface, it has completely different DOM.

Performance comparison of #FindBy() and driver.findElement()

I am using selenium framework to automate a web application wherein basically, driver.findElement() is commonly used. but I got the suggestion that #FindBy() works faster than driver.findElement(). suggest me which is better to use ?
When the code - PageFactory.initElements(....) is run it creates Proxy objects for all the fields which are annotated with #FindBy (or even #FindBys and #FindAll). So initially no searching of WebElements are performed.
Then if something like element.sendKeys(...) is run, the actual WebElement is searched using driver.findElement(...) before sendKeys() is run. Then if the same sendKeys() code is run the element is found again.
But if you add the CacheLookup annotation to the field then the second lookup is not performed but element is returned from the cache. So there is a performance gain. But the problem occurs in a javascript or ajax heavy page, stale element exception can show up.
For any non-trivial application testing use the PageObjectModel framework. Makes things organized and not littered with findElements and locators, even if you do not use the CacheLookUp annotation.

Two different syntax structure for Selenium

I'm using using AutoHotkey to drive SeleniumBasic v2.0.9.0
I'm new to Selenium and have been looking at a lot of different pages discussing how to get/set elements on a webpage. I've noticed there seems to be (at least )two different types of format for syntax.
Here are two examples:
1. driver.findElementByID("search_form_input_homepage").SendKeys("hello")
2. driver.findElement(By.id("search_form_input_homepage")).SendKeys("hello")
In my case the first one works but the second throws an error saying No such interface supported. I'm just curious of the origin of the second structure. Is it from Selenium 3?
Here is the Answer to your Question:
driver.findElementByID("search_form_input_homepage").SendKeys("hello") : Is in use through the VBA module maintained by #FlorentB.
driver.findElement(By.id("search_form_input_homepage")).SendKeys("hello") : Is in use through the Java bindings of Selenium.
Let me know if this Answers your Question.