How to run webdriver and JMeter code in Eclipse using Java - 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

Related

How to run same test on multiple urls like 100s of them using selenium ( Java)

I am new to selenium. Currently, I am working on creating a program that will test multiple report url in browser using selenium.
Scenario: xml file will have multiple url declaration.There will be separate property file for login details. main java program will read xml file and run test using selenium one by one using. If test case passed send an email notification and if it fails also send email notification. Email will have detailed report like which url failed or passed.
Currently my program is able to read multiple urls and perform the testing. Can anyone suggest me high level overiew on how can I achieve the above scenario in the best way possible? Any help will be appreciated.
you can use TestNG framework where you can take help of dataproviders.
create a method to read data from xml and return in 2d data and declare this method as dataprovider. testNG provides the flexibility of using this dataprovider in parallel which comes in handy while running your test

Is there any automation code that always works perfectly without exceptions

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

how to Load test a java api (Jar) using modern tools?

I have a simple java code integrated with Apache Camel which also uses camel-kafka component for logging messages in kafka topics. I have created a class which handles single request.
Using threads I can create various threads to invoke above class method to log messages.
Currently I need to load test this JAR using a tool. I want to know a tool that have very low learning curve.
Load test:
increasing users to allow multiple messages to be logged concurrently
variation of messages to increase/decrease message size
Time taken by specific users to log specific messages.
I have gone through
JMeter (learning curve is big)
JProfiler (it does not load test but monitors the application if I am
not wrong)
Netbeans Load generator (again it uses JMeter)
Download groovy-all-*.jar and drop it to /lib folder of your JMeter installation
Restart JMeter
Add Thread Group to test plan. Set desired amount of virtual users, interations and/or duration.
Add JSR223 Sampler as a child of the thread group
Choose "groovy" in the "language" dropdown
Put your "simple java code" in JSR223 Sampler's "Script" area
Save test plan.
Run it.
Was that so hard?

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 test my Java code that is using Selenium?

I have a Java application that is scanning a website using Selenium. It is crawling all the pages of the website. Some of these pages are generated dynamically by selecting a combination values, clicking some buttons.
The purpose of this application is to crawl through all the pages of the website and save the HTML source and a screenshot of all the pages it comes across. The content and structure of these webpages keep changing over time.
The application is running fine, but the methods calling the webdriver and fetching the elements to enter a set combination of values and clicking buttons to get to all the pages need to be updated quite often as the HTML structure of the website is changing frequently.
Now my question is that:
How can I test the functionality of my Java methods calling the Web Driver using Unit Tests
How should I approach the unit tests to test the stability of my code that is finding HTML elements, filling in values, clicking buttons, getting the HTML source.
Currently I save a sample HTML file and test my code against it. But since I have to update my code and unit tests along with every HTML structure change, that defeats the purpose of unit tests, if I have to updated my unit tests as well (since the values on the page also change).
Please help me find an efficient or correct approach to testing my code using unit tests.
I have been working on the same feature in this project Revolance UI Monitoring to do reviews on changes in the UI acrross several versions.
To answer your question, I solved the testing problem by using PhantomJS with a mocked website. As you designed yourself the mocked website, you know what should be the expected outcome.
I hope this help!

Categories