Why does my Selenium Automation test suite fails intermittently? - selenium-webdriver

My test suite fails intermittently throwing error as 'Element not found' even after putting all sort of waits(waitForPageLoad , Thread.sleep and explicit wait for element to be loaded in a page) it fails intermittently.
When running the same test case individually runs fine and also sometimes along with n number of test cases it works fine.There is no consistency to which test case will fail when I try running the full automation test suite consisting of 30 to 40 test cases.
Can anyone please help me to find the root cause for the same.
I am running the test suite through maven in following phase:
<executions><execution>
<phase>site</phase>
<goals>
<goal>send-mail</goal>
</goals>
</execution> </executions>
Does it have any relation in which Maven phase am running ?

I don't know about Maven, but you are waiting for the page to load but that doesn't necessarily mean that the element you want has loaded.
I think you need to be certain that the element you wanted was actually present, and if it was present, was it interactive.
You say you are using Thread.sleep() but this will only wait a specific period of time without any intelligence regarding the presence of elements on a page.
What you should be doing is polling for an element to become avaialable. Try looking at Explicit Waits http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp
Here you combine two elements WebDriverWait and ExpectedCondition so that you wait until the element is clickable for up to say 30 seconds then fail.
Also you say that the test runs fine in isolation but poorly in a run. This tells me that you aren't resetting your environment to a good known state. A simple example would be closing your browser after each test and a better way would be to fire up an immutable VM (or docker container) for each test case so that you get the same thing over and over again.
Although there are cases where you would want to not do that and see how your tests handle a soak.
Getting stable and reproducible though should be your main concern. Have a look at when the test fails and confirm that the element you wanted was actually available at that particular time. Memory leaks etc.. can slow the browser down and make a sleep of 3 seconds more like 20. If you are going to wait to cover a defect use huge sleeps (remember polls are better) to cover it and get you stable while the defect is worked on.

Related

Selenium Webdriver + Jmeter + StormRunner for Performance test

I wanted to try out integration of Selenium Jmeter and StormRunner. My end goal is to do Load testing with 'n' number of users on StormRunner
What ? - For e.g. I have Selenium Script, convert it in to Jmeter (I can get this information from many sources)
Then my Jmeter script should get ready
Then upload Jmeter script in to StormRunner and pass the necessary parameter through Jenkins and run the load test.
I really want the opinion here about feasibility and whether it is in right direction or not.
Idea here is that Automated Load/Performance test
Selenium is a browser automation framework and JMeter acts on HTTP protocol level so your "Automated" requirement might not be fulfilled especially if your tests are relying on client-side checks like sorting or waiting for element to appear.
Theoretically given you properly configure JMeter it can behave like a real browser, but it still not be executing client-side JavaScript.
If you're fine with this constraint - your approach is valid, if not and the "automated functional test" requirement is the must - consider migrating to TruClient Protocol instead
Why wouldn't you covert your script to a native Loadrunner/Stormrunner form of virtual user?
You should look at the value of what you are trying to achieve. The end value of a performance test is in analysis. Analysis simply takes the timing records and the resource measurements produced during the test, bringing them together on a common timestamp, and then allowing you to analyze what resource "X" is being impinged when timing record "Y" is too long. This then points to some configuration or code which locks up on resource, "X."
What is your path to value in your model? You speak about converting a functional test script to a performance one. Realistically, you should already know that your code, "works for one," before you get to asking, "Does it work for many?" There is a change in script definitions which typically accompanies this understanding.
Where are your collection of resources noted? Which Resources? On which Hosts? This is on the "path to value" problem where you need to have the resource measurements to diagnose root cause of poor performance.

Parallel execution causing test data mixing across tests

I'm automating Selenium tests using TestNG's data-provider-thread-count which runs tests in parallel. But I could see that username, password of one test i.e. driver is being passed to another one.
I analyzed my code and there I could see that for each thread I've Webdriver instance and there is no objects which are shared across, hence I think there is no chance of sharing test data of test with another.
Could you please let me know what could be other possible reasons so accordingly I'll analyze my code and try to find root cause?

SpecFlow issue - Before Scenario/Feature looping through multiple times

Any one else having this issue?
I have used [Scope(Feature = "FeatureName")] at the top of my steps so that only these steps are usable for that feature. I have then used a [BeforeScenario("taggedScenario")]. Multiple tests have the same tag so i would expect this to be run each time before each of the tagged tests. However when i go to run a single test it runs through the before scenario multiple times before the starting. I would expect it to run once, then run my test. If I was to run 2 tests with the same tag i would then expect it to run the before scenario before each test.
Has anyone else come across this issue and if so has anyone managed to resolve it?

Selenium automation report

I am using Selenium framework for my test cases execution.
I need an instant report of test cases that are passed while the full suite is in execution currently.
For Eg: There are 100 test cases in suite and five have run of which 3 passed, 2 failed and I need these instant report while the suite is in-progress. Can you please help me with this task?
You can use ExtentReport.
You can use it to log your test steps and once its done it will generate a report to show your results.
For what your looking for, ExtentReport uses a "flush".
If you call this flush after each test step it will amend the step and create the report.
This is something I'm looking into myself at the moment, so I wouldn't consider this an answer but something I've stumbled across myself, hope it helps.
Here is how to set up ExtentReports on your project with examples - http://www.ontestautomation.com/creating-html-reports-for-your-selenium-tests-using-extentreports/
You must use it in conjunction with a test runner eg. TestNG or JUnit.
For what you are trying to achieve is slightly different to the example. You need to call a flush after every test step so it will amend to the report after the step is completed rather than when all the tests are completed. Its not something I have done before but it was explained to me like the following
Just call .flush() after every test instead of once at the end of your test run. BUT you need to make sure the ExtentReports object itself is only initialized once, instead of being reinitialized at the start of every test. For example, I used TestNG. The ExtentReports is called once using #BeforeSuite, but the .flush() is called after every test using #AfterMethod. I hope this makes sense.
The only thing that can’t be solved via code is the HTML refresh as this is outside the control of the ExtentReports library (it doesn’t know where you’ve opened the actual HTML file). But this can be taken care of by using a simple browser plugin as I said. At least for Chrome there are a lot of them, just do a Google search for ‘chrome auto refresh’.
Hope this helps. If you need anymore advice don't hesitate to contact me.

How to overcome the random failing of my selenium webdriver-java script?

Currently, i am running my selenium webdriver - java scripts, there is a strange issue which is cropping up these days. My scripts run absoulutely fine and when I re-run them.. sometimes my scripts enter the values via sendkeys() in some other fields as a result of which my entire script fails.
I dont know the real reason behind it, I know the scripts what i am running are pretty simple and straight flows.. Is this because of my application response issue? Because I have given wait commands also to tackle the same.But when I have re-run the same scripts again it enters the values in some irrelevant fields..
Note: I dont change any of my codes while rerunning it... Its more frustrating
Is this normal when you run Selenium webdriver-java scripts??
Please advise me how to tackle this issue because I am not aware to deal with this issue
You might need to figure out if your elements locators are changing dynamically each time you run and then look at your code locators to be more appropriately handling the change. Other than that I see no reason why the elements being interacted with, change randomly.

Resources