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

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

Related

what exactly Cucumber test, it is about service interface or function? and do it need to connect DB to get real data?

I am just the beginner of java Cucumber BDD testing, I want to know in what case we need to use Cucumber to test?
Does it relate to service interface or the whole function(maybe combines serval interface)?
Does it need to retrieve the real data from Database?
please answer me, thanks.
I have built up the technical part, configured the maven dependencies and already integrate Cucumber with SpringBoot.
I just don't know which part Cucumber could deal with. it's not relate to coding, it's about the concept.
none
Cucumber is a tool best used to exercise a piece of functionality that is important to the business. It creates additional overhead in comparison to other test tools to allow the thing that describes and instigates the test to be written in the language of business rather than in the language of code.
Because of this extra overhead Cucumber is best used for big things like
buying a product
registering to use an application
making a complaint
...
rather than little things like
ensuring my password has a symbol in it
ensuring that my complaint has an email address with it
ensuring that have checked box A and not checked box C
In particular Cucumber is not a tool for doing any kind of exhaustive testing. So if you had an online form with 15 fields on it, Cucumber would be good tool to show that you can use the form to do something, and a good tool to use to show that an error appears when you input bad data, but a bad tool to deal with all the possible combinations of bad data you could enter (you should use a unit test tool for this).

How to enter input data from an Excel to a Selenium project?

I would like your support by providing information (scripts, videos, or books) regarding how to enter input data (for example: username and password) to a selenium project from an Excel file using Cucumber and Serenity DB.
Is it possible?
Thanks for all.
By principle, Cucumber doesn't supports data from external files. Instead it encourages to provide examples with scenario. However there are few non standard way available with cucumber to use examples from the external file. One of them, you can refer in grasshopper's post.
Another alternate is using gherkin with QAF which provides lots of features inbuilt data-providers including XML/CSV/JSON/EXCEL/DB. Here is the step-by-step-tutorial to start with.
From the FAQ:
"We advise you not to use Excel or csv files to define your test cases; using Excel or csv files is considered an anti-pattern.
One of the goals of Cucumber is to have executable specifications. This means your feature files should contain just the right level of information to document the expected behaviour of the system. If your test cases are kept in separate files, how would you be able to read the documentation?
This also means you shouldn’t have too many details in your feature file. If you do, you might consider moving them to your step definitions or helper methods. For instance, if you have a form where you need to populate lots of different fields, you might use the Builder pattern to do so."

Automatically generate Gatling scenarios

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?

Is there a way to use the FitNesse / SLIM engine to launch test suites designed with FitPro (,suite + .fit web pages)?

My company is using FitPro + FitLibrary to test our applications. Our main test suites are .suite files and they invoke FIT tests pages, which bear the .fit extension (contents
is HTML).
Our application Fixtures are built on top of FitLibraryRunner.jar (a release issued on 01/28/2007), and we have a .bat/.sh script which launches our FIT tests suite using
com.luxoft.fitpro.runner.TestCaseRunner, which is part of the fitpro.jar library.
This setup is convenient for us because we provide the same application but customized for many customers, and all you need to run FIT tests is fitpro.jar among your classpath, and you don't depending upon other stuff.
As FitPro seems to be no longer maintained, our alternative would be to switch to FitNesse.
Now, it would seem as per my understanding that FitNesse does not offer runners that would allow executing FIT tests suites outside of its wiki. Let me precise that the usage of a Wiki is not really useful for us due to us packaging the same libraries but in differents stages of development, and to many customers.
I would like to know if any of you could ever succeeded in launching the FitNesse/SLIM engine outside of the wiki context ? I am looking for a way to invoke a Runner provided with FitNesse, that reads a main suite test file (.suite) and produces an HTML or XML-based report as output, just like the way we do with FitPro.
I am also told that I could not use the .suite and .fit pages we have created with FitPro over the years.
Thanks in advance for any feedback!
J-C
If you don't want to use the FitNesse wiki, then FitNesse doesn't add any value for you. FitNesse renders HTML from its wiki pages and passes them to a test execution engine, like Slim, FitLibrary, fitSharp, etc. FitLibrary and fitSharp can also execute tests sourced from HTML files. I haven't used FitPro but it appears to feed FitLibrary with tests from its own .suite and .fit files. Your best bet may be to use FitLibrary's FolderRunner and organize your suites into folders of HTML files that FolderRunner can process.

How to implement TestNG in Keyword-driven and Data-driven frame work?

I am new to Selenium and i want to crate a test case of my dummy website for practice purpose. I have learn about Keyword-driven and Data-driven frame work. I also learned about TestNG but i am in a confusion that how to implement all these things, I want to automate full website with reports.
You are mixing a lot of orthogonal concepts together. Rather than unpack them, please allow me to start from the beginning.
First, you want to use the Page Object Pattern with Selenium. This pattern decouples your tests from the internal structure of a page--via a services abstraction where all the test "knows about" is the services provided by the page. This way the structure of a page can change (as it certainly will during the project), but your tests remain the same (assuming the services don't change, but of course you want the tests to change in that case).
Next, you have tests that will use PageFactory and other aspects of the Selenium API to perform assert's and verify's on the page objects. These tests can be written as TestNG or JUnit tests.
So you will have a TestNG test (since that seems your preference) where the test methods will perform assert's and verify's on page objects by using the Selenium API.
Hope that helps.
I think what you were seeking for is #DataProvider, which TestNG provides.
All you need is to return data in type :Object[][] or Iterator<Object[]> ,then use this data provider in your testcase.
The testcase will be run (length of your Object[][] or Iterator<Object[]>) times

Categories

Resources