Is there any automation code that always works perfectly without exceptions - java

I am new to test automation (Selenium WebDriver) and I have created a good automation code, that sometimes runs perfectly, but most of times it just fails, without any good reason, with no code changes.
Is this normal or the problem is my code?
I just want to know if anybody faced that problem before or it's just me.

Tests that rely on external systems are often a better fit as integration tests, and Selenium tests definitely belong in that category. If you are using Maven, you can run the Selenium tests using the Failsafe plugin instead of Surefire. This allows them to "fail" without breaking the build, but you can still have ordinary unit tests that must succeed.

With reference to https://sqa.stackexchange.com/questions/9007/how-to-handle-time-out-receiving-message-from-the-renderer-in-chrome-driver , following are recommendations :
Solution 1: There are some plugins like flash player which may hangs the browser inconsistently waiting for some resource during test run, try disabling such plugins while starting the test using the chrome switches. http://peter.sh/experiments/chromium-command-line-switches/
Solution 2: The browser might hang waiting for some third party ads. Try disabling ads using some ad blocker extension or block the url pattern using the custom proxy configuration.
For inconsistent browser hangs, Try to find which process hangs the browser. 1.Unlike firefox chrome creates separate process for browser, tab, extension and plugins. 2.When the browser hangs check is there any new process(shift+Esc) like Web Worker:blob appended with an third party url, then follow #2 3.or else if there are more separate process opened for plugins try #1
Please refer to below link :
https://sqa.stackexchange.com/questions/9007/how-to-handle-time-out-receiving-message-from-the-renderer-in-chrome-driver

Related

How to run webdriver and JMeter code in Eclipse using Java

Below is my requirement :
(1)I need to do UI performance testing .
(2)At the end of the test I want jmx file to be generated,I do have the batch file that will convert it to jtl and then to html report.
Answers not known :
(1)I did browse through a lot of links that explained how to execute webdriver code using JUnit in JMeter. However I don't want to do that[run webdriver code in JMeter] and want my code to be a standalone code using HTMLUnit(headless browser) performing authentication and then the remaining click actions[Click on multiple links] ....Behind the scenes jmeter should record performance of every page and at end of test ,dump the results.Also it should be irrespective of testng /junit .Does anyone know if this is possible and can redirect me to the appropriate link.Thanks!
JMeter has nothing in common with the UI performance testing, as per JMeter main page:
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
Both JUnit and TestNG automatically record function execution duration, you can build your test in such a way that measurable actions would be annotated with #Test annotation so the time will be automatically recorded.
In addition you can consider using Navigation Timing API from your WebDriver tests in order to get more information regarding page loading events.
If you still want to run JMeter tests from Java code - check out Five Ways To Launch a JMeter Test without Using the JMeter GUI article, it covers both running existing .jmx file and creating a new JMeter test purely using JMeter API from Java, however it is not applicable for your use case. The recommended way is to:
Create the main load using JMeter
Measure client-side performance using Selenium

Is Appium able run a test that touches 2 different apps, one iOS and the other Android at the same time?

Context: I am working with a project that involves an android-controlled hardware and an iOS app that talks to that android device via websocket. We are in a good shape in terms of lower level (API, unit, contract) testing, but there's nothing to help us with the UI part of it.
UI automation, especially end-to-end is not my favorite way of testing because it is flaky and slow, and I believe it's purpose is only to guarantee that the main user flows are executable rather than every single piece of functionality.
So I developed a suite that includes both the android and the iOS code and page objects, but right now the only thing I can do is run each one of them individually:
Start the appium server and appium driver for android, run the android app suite
Start the appium server and appium driver for ios, run the ios app suite
But that is not quite exactly what I want - since this is going to be the only test case, I want it to be full end-to-end; starts appium server, starts android server, also start appium drivers for both, run test that places an action on ios and verifies that android is executing it.
I don't want to have someone manually running this thing and looking at both devices. If this doesn't work, android and ios suites are going to run separately, relying on mocked counterparts.
So I am throwing it here to the community because none of the test engineering groups I posted to were able to come up with an answer.
I need to know if anyone has ever done or seen this to shed me a light, or if anyone knows how to do it.
Can Steve Jobs and Andy Rubin talk?
I would look into starting 2 appium instances via command line on different ports and then connecting each suite to a given appium instance. Then at this point you just need to properly thread each suite so that you can properly test your code. To do that you will need to add dependencies (can be easily done using TestNG).
Steps:
1) Create a thread for IOS and Android Suites
2) Run each suite on a different appium session (aka different ports)
- You will need to know how to run from command line for this
3) Setup your tests to depend on one another (I recommend using TestNG as the framework)
4) Use threading logic to properly wait for tests to finish before starting. Yields and Timeouts will be very useful, as well as TestNG dependencies, it will save your life given what you are doing.
NOTE: Appium has a timeout functionality where if a session does not get a command in 60 seconds by default the session is destroyed. AKA make sure you increase or find a way to turn off that timeout.
Additionally as a recommendation I would advise the use of TestNG over JUnit. JUnit is a Unit testing framework, meaning you are testing specific functional units. This however is not ideal for app automation as many areas of an app depend on prior functionality. For example if you have a login screen where the login functionality is currently broken you don't want to run all of the tests the need the user to be logged in to pass. This would cause not only a lot of fright when a large portion of your tests fail, it will also make it harder to track down why it failed. Instead if you have all of these tests depend on the login feature passing then if the login fails there is a single error which can then be fixed, and all the tests that depend on the login feature don't run when you know they are going to pass.
Hope this process helps, sorry I obviously can't send out code in this as it would take hours for me to type/figure out.
Problem solved, it was as simple as it looked like.
What I did was to implement an abstract class that builds drivers for both android and ios with their capabilities and specific appium port, instantiating their respective page objects as well. All the test classes extend this abstract class.
Then I divided the suite in 3 pieces:
One for the Android only, which only accesses the page objects for android;
One for ios, which also accesses only the page objects for ios;
And a third test that spins up both ios and android and controls them both.
To avoid always starting two appium servers and also avoid always downloading the latest app versions for both android and ios I created gradle tasks for each platform, so the CI jobs can call only the task that prepares for the platform it has to test at a given moment.

Using the same Firefox Window to run multiple tests in Selenium WebDriver (Java)

I am running test cases on selenium Webdriver in Java. The first test case opens the browser window and performs the test.
After the first test case is complete I want to utilize the same browser window to run the next set of multiple test cases.
How can this be achieved? Can someone point me in right direction?
Don't quit your browser in the "TearDown" part.
Navigate to a common URL in the "TearDown" part from where multiple test cases can start.
Thus you will be able to utilize the same browser window to run the next set of multiple test cases.
You can reuse a browser in multiple tests using Spring to inject it. This can be faster for running a suite. But, and it's a big but, if one tests "dirties" the browser (e.g. with cookies), then you could easily find yourself spending more time debugging flaky tests that you save on run time.
There's an example here: http://www.alexecollins.com/tutorial-integration-testing-selenium-part-1/

How to run Selenium tests with single click or single command?

I'm writing Selenium tests using Java + Maven + Selenium WebDriver. Our customer wants these tests in such a way that they can run tests easily without much technical stuff needed.
I've all my tests under src\test\java folder. Is there any way where I can give jar file or so to the customer and they can run tests by simply clicking on it or by hitting some command on the command line.
Please point me to documentation or video using which I can achieve this.
I've been using Visual Studio to write my Selenium tests in C#. I am able to build my project to a console application in Visual Studio that contains the required files like the Chrome webdriver. It can be run from this single application file with one click. The console then prints out if the test is a success or if their are any exceptions. You should also be able to integrate a headless browser like selenium has on their site. This would allow the test to be run with one click and no browser will pop up while the tests are running.This is all the experience I have and it has worked well for me. Hope that this information can help a little.

How to run a test case without opening the browser window?

I have created a set of test cases using Firefox Driver in Eclipse IDE.
But now I need these test cases to run without opening the browser window. How can I achieve that?
Presently I am using Firefox Driver Web Driver that runs in Firefox Browser.
Can some one help me with an example?
If you do not need to think about compatibility of different web browser, you could try Celerity. It could be run automated test script without any browser window.
http://celerity.rubyforge.org/
It is based on JRuby, and is very easy to learn and use.

Categories