5

Am a beginner in Selenium and am trying to learn selenium on my own by googling. One thing which I noticed was in many of the posts which I read about selenium the name of the framework by name "TestNG" is common. I have understood that its a framework and with its Annotations and Test case compliance power, we can organize our Selenium test cases using the TestNG. But I have few queries regarding the same:

  • By using the TestNG framework, should we modify the Selenium Code which we write?
  • Are there any Coding standards which has to be mandatory used while using TestNG?

Please, do clarify my doubts. And even recommend some of the blogs/sites from where I can learn Selenium as a beginner.

1
  • TestNG is a test execution engine - the part that identifies methods as test cases and executes them, similar to the other ones MichaelF mentioned below. Other common ones are all of the xUnit frameworks, so JUnit is another common one for code written in Java. – Sam Woods Apr 22 '14 at 0:09
7

I have used Selenium and TestNG in the past to manage a lot of my automation and as Siva mentioned you do have the basics down. While TestNG is one of the most common Frameworks out there, it is not the only one, and you can use whatever one works for you. So long as you can import the Selenium drivers you can use any framework in which you are familiar, I've used Gallio, TestNG, PowerShell, Fitnesse/Fitnium as a wrapper and even Python/Robot to drive the tests. Find which one works for you.

Look for a way to organize your tests that make sense to you and your Users, I have added SpecFlow on top of my Test Cases to make the higher level descriptions more readable to Business Users. This allowed me to code with Selenium/Web Driver behind the scenes and do the kind of testing I wanted, while presenting a readable set of Test Cases to my Users.

As to your questions:

  1. You should not need to modify your code while using TestNG, although it depends on what features of TestNG you take advantage of; you probably could though I didn't when I originally set up my framework.
  2. Coding Standards I tend to think of as being specific to your company, if you don't already have some standards then check with your developers and see if you can co-opt theirs this way you have a standard across departments. Code then looks the same in your organization and it is easy for anyone to review, or even give your test code a code review - which you should do anyway.

There are plenty of places to learn, but it depends on your level of expertise. Check the examples at the Selenium site first, then if you feel comfortable you can look for more.

1

You seem to have picked up basics correctly. I can add my inputs

Selenium is mainly for web test automation. Predominantly you will simulate user actions on the website. The code generated by IDE need to be modified to make it data driven / organizing test scenarios etc

If you are going to write automation code (you need to manage input data handling, pre-test execution, post test execution, tracking errors / failures etc). TestNG framework provides all the above listed features by itself reducing your effort to reinvent the wheel.

Refer basic examples from testng.org, seleniumtests.com.

This forum can provide lot more useful pointers / specific help if you run into issues.

0
1

Short answer:

  • Selenium is a testing framework to test specifically the UI of the application how it behaves on browser.

  • TestNG is a testing framework to test the unit, functional, E2E, integration testing of the application.

Point of confusion (long answer):

Most of the time, we find use of TestNG with Selenium (mostly in JAVA world). This coupling raises few questions:

  • Can Selenium be useful with out any such framework like TestNG?
  • Do I have to use TestNG whenever I use Selenium?
  • If used combinedly, what purposes Selenium & TestNG serve differently ?

The answers to the questions are as follows:

  • Selenium can work independently without TestNG or any such testing framework and serve your UI testing need on browser.

  • You may not need to use TestNG at all OR you can use a replacement of TestNG like JUnit or whatever suits you.

  • In most of the cases we use them together, because they complement each other. Selenium gives you the opportunity to test how your UI controls behaves on the browser. TestNG gives you ability to extends the UI testing into E2E testing, integration testing.

    (i) You can use the same test case in more than one browser parallelly using TestNG (save time and effort).

    (ii) It helps you manage test cases in a better way and generate standard test reports. Note that, test report generation is not a core feature of Selenium. If you don't use a framework like TestNG, you have to write custom code to generate and store test reports for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.