Automatically generate Gatling scenarios - java

We currently maintain our Gatling simulations manually if a list of REST calls of a page changes. If a developer extends a page with a new call, he has to remember to add that call to Gatling simulation.
How to make sure a simulation is in synch with a web page implementation?
My approach would be to write a Selenium based test and get from a WebDriver a HAR files then parse it to generate a Gatling scenarios. Though possible, this approach feels awkward and I ask myself if there is an established way of solving the problem?

I would believe that the best way to do this is to have a custom Java Class writing the scala files for gatling.
Should take the url and parameters as input and produce a new scala file or just append to an existing scenario.
That should be the best way to do it.
But still it will be better if you directly use the recorder.sh that comes with the gatling setup.

To make sure a developer doesn't forget keeping Gatling simulation in synch with web page implementation, you need to ask him if he executed the simulation as a part of his responsibility to test his own changes.
If this is not how your team works maybe a Quality Assistance is needed?

Related

How to Build a Data Driven Selenium WebDriver + Java + TestNG Framework

I'm planning to automate some website using Selenium WebDriver + Java + POM(Page Object Model) + TestNG.
I've all other WebPages common for the given website but for each transaction one WebPage which is almost like a form would be different.
So, I've following choices.
Have a Page Object Model (POM) Created for all static common pages and Start creating POMs for the pages which differs in each transaction.
Have a Page Object Model (POM) Created for all static common pages and using some external data source (XML, Excel etc) I can generate the tests for that perticular page.
I'm in favour of second approach here as I don't need to write code again for each new transaction just because there is one page is different?
Any thoughts? or anybody implemented something like this already?
Yes 2nd approach- 'Page Obj model' based is best to keep your code isolated and easily maintainable.
For your test data maintenance I'd suggest you using Cucumber based (BDD driven) framework.
It goes very well with automation FW (POM, Selenium, Java, TestNG/Junit and Maven based) projects.
By using cucumber you need not depend on any other source of test data, i.e. excel or xml, this can easily be maintaned with feature files of cucumber.
Also BDD gives you the main advantage of keeping 'BA-QA-DEV and Management' on same page.
If you dont want to use Cucumber/BDD, then you can use Test NG data provider feature with Excel to achieve better test data management.
If you want to learn Cucumber/BDD-> there are lots of very good video tutorials available online. One of my Fav is here-
https://www.youtube.com/playlist?list=PL6tu16kXT9PpteusHGISu_lHcV6MbBtA6
for web reading:
https://www.lambdatest.com/blog/automation-testing-with-selenium-cucumber-testng/
Happy Testing!
I have worked in similar kind of project. I would suggest to with #1. The reason is that might be possible in future you find difference in web pages, So common function will not be always applicable to each page.
So if you go with #2 as of now then its fine but you gonna end up by following #1 in such cases.
The above answers are mixing the Page object model with a data-driven framework.
Basically in data-driven framework, the data is read from an external file
Well if you want to build a simple pure data-driven framework then it should have
Independent tests
All tests should read data from JSON/XML/YAML/XLS... any source
Properties file having your locators and other settings
You should also create a base class which will have the common reusable functions which can be used in tests
You should make it in such a way that running on grid is easy and by just chaning external flag.. tests should run in GRID
Proper HTML reporting with screenshots, errors, failures should be done
Also watch this video
https://youtu.be/s-W8pw9GnWc

Would testing my Java Servlet be neccessary?

I just wanted to ask if it is necessary to test the java servlet that calls another java method (in another file I might add) to do the bulk of the work.
Like for instance, my java servlet currently only is being used to get parameters and displaying the results of the method that was called in html format. So I am only planning on testing my main java file that does all the work!
I am not very familiar with testing so if there would be specific ways to test this simple Java servlet, please let me know!
Testing your Java Servlet or for that case, any Java code is very necessary. The way we always tend to write any code is called the HAPPY PATH, which sometimes overlooks possible scenarios that might break your service. It is always a best practice to code via the TDD way (test driven).
You can Unit Test your Servlet alone, if it does perform the main logic as a single unit.
You can perform Integration testing if your Servlet along with other Java code performs the logic as a whole.
There is this question on SO which covers almost all the details on how to perform this and also the various choices to choose from to perform them.
Hope this helps!
Like for instance, my java servlet currently only is being used to get
parameters and displaying the result of the method is has called in
html format. So I am only planning on testing my main java file that
does all the work!
Ideally, you should Why so?
If something messy happens and servlet broke befoe calling the Main business logic
Testing how parameters are fetched so you can be sure which kind of parameters my Servlet can handle (I personally don't like junk values to be passed to my business logic).

How can I split my Java Selenium tests into separate classes?

I'm currently working at my job to perform GUI testing of our web page using Selenium 2 via Java in Eclipse. I've been trying to program my tests in such a way that I maximize the amount of code I can reuse and as a consequence I now have a lot of helper methods that function almost like a framework. This has lead to my test class becoming fairly bloated with only one method used as the actual test and the rest being the implementation of the test.
Currently I just run the testing right from Eclipse with all my methods being static.
From what I understand there are a couple different ways I could try to separate things out:
One way would be to put all the methods into a class I use as a framework and extend it when writing an actual test, but I don't know if having a framework in a framework (Selenium) makes sense.
Another way would possibly be making my helper methods into an object where I can have one of these objects for each test. I don't know if this is good practice though, or if it will cause problems down the road. It would also mean I'd have to type more to do the same amount of testing.
My main questions are:
What's the best way to split up my testing class into test classes and an implementation class?
Is what I'm doing outside the intended usage of Selenium?
The best practice is that create a page object model for each web UI.That will help you to access the web element easily.selenium provide that feature and you also have to do some R&D things.
Home_Page.lnk_MyAccount(driver).click();
LogIn_Page.txtbx_UserName(driver).sendKeys("testuser_1");
LogIn_Page.txtbx_Password(driver).sendKeys("Test#123");
And put all selenium related actions into a one class.like Action.click(),Action.search(), or what ever your common set of actions.
Next thing is that reusable code implement via a function.let say login(usernName,Password) then handle the login code inside that.and you can reuse thease codes in your other places.always try to modularize your implementation.

Selenium Grid Execution using my own framework

I have developed a micro-framework in Java which does the following function:
All test cases list will be in a MS-Access database along with test data for the Application to be tested
I have created multiple classes and each having multiple methods with-in them. Each of these methods represent a test-case.
My framework will read the list of test cases marked for execution from Access and dynamically decide which class/method to execute based on reflection.
The framework has methods for sendkeys, click and all other generic methods. It takes care of reporting in Excel.
All this works fine without any issue.
Now I am looking to run the test cases across multiple machines using Grid. I read in many sites that we need a framework like TestNG to have this in Grid. But I hope that it could be possible to integrate Grid in my own framework. I have read many articles and e-books which does not explain the coding logic for this.
I will be using only windows 7 with IE. I don't need cross browser/os testing.
I can make any changes to the framework to accomplish this. So please feel free.
In the Access DB which I mentioned above, I will have details about test case and the machine in which the test case should run. Currently users can select the test cases they want to run locally in the Access DB and run it.
How will my methods(test scripts) know which machine its going to be executed? What kind of code changes I should do apart from using RemoteWebDriver and Capabilities?
Please let me know if you need any more information on my code or have any question. Aslo kindly correct me if any of my understanding on Grid is wrong.
How will my methods know which machine it is going to be executed? - You just need to know one machine with a grid setup - the ip of your hub machine. The hub machine will decide where to send the request to from the nodes that are registered with, depending upon the capabilities you specify while instantiating the driver. When you initialize the RemoteWebDriver instance, you need to specify the host (ip of your hub). I would suggest to keep the hub ip as a configurable property.
The real use of the grid is for parallel remote execution. So how do you make your tests run in parallel is a thing that you need to decide. You can use a framework like Testng which provides parallelism with simple settings. You might need to restructure your tests to accomodate testng. The other option would be to implement multithreading yourself to trigger your tests in parallel. I would recommend testng based on my experience since it provides many more capabilities apart from parallelism. You need to take care that each instance of driver is specific to your thread and not a global variable.
All tests can hit the hub and the hub can take care of the rest.
It is important to remember that Grid does not execute your tests in parallel for you. It is the job of your framework to divide tests across multiple threads and collate the results . It is also key to realise that when running on Grid, the test script still executes in the machine the test was started on. Grid provides a REST API to open and interact with browsers, so your test will be using this rather than opening a browser locally. Any other non-selenium code will be executed within the context of the original machine not machine where the browser has been opened (e.g. File System access is not where the browser has opened). Any use of static classes and globals in your framework may also cause issues as each test will acces these concurrently. Your code must be thread safe.
Hopefully this hasn't put you off using Grid. It is an awesome tool and really easy to use. It is the parallel execute which is hard and frameworks such as TestNG provide this out of the box.
Good luck with your framework.

How to Accelerate Java Web Testing

I am coding an intricate method in a Spring Controller that takes as input request.getParameterMap(). In developing the method iteratively, each time I make a tweak, I have to Deploy, and then go through the steps on the web form.
That process can take minutes, just to tweak a small code change.
Are there any tricks or methods to speed up this process? All I really need is the input from request.getParameterMap(). Can I serialize that Map data somehow, and re-use it?
I am using Netbeans, if that is relevant.
In my experience the best is to setup a JUnit test, which doesn't use the web server at all, but just instantiates the controller, calls the method and checks the result.
Since your controller wasn't written from the ground up for this kind of approach, it might be quite some work to get this going at this stage. If you post the method in question we might help with this.
The next best thing is setting up an integration test, which starts up the application server, executes the request (possibly through the actual web gui using selenium or something).
Still a lot of work, but the difficulties are less dependent on the current workstyle.
As a final work around you can try to make the roundtrip for a manual test faster. There might be IDE dependent possibilities so you would have to let us know about the IDE in use.
I haven't tested it, but many people praise JRebel for this kind of thing, so you might want to give it a try.
If you don't want to fill the web form again and again try Jmeter(It's a free load testing tool).
Create a test plan with -> set number of threads to 1 --> http request sampler -> set method to post and add post parameters. Once everthing is setup fire the request
please check this link below for reference
http://community.blazemeter.com/knowledgebase/articles/65142-the-new-http-sampler-in-jmeter-2-6

Categories

Resources