Are there any advantages of using Testng with cucumber? - selenium

When creating automated tests with selenium, I thought one would use easier cucumber with selenium or testng with selenium or just junit with selenium although using only junit is not very popular. I have recently found out that you could use cucumber with testng but I don't see what is the gain of doing this. If someone is using both of them together can you tell me why ?
EDIT:
Using Testng over junit has many advantages. My question is if i use cucumber does it still make a difference or not anymore.
P.S I am not trying to start this tool vs this tool war

The answer that you seem to be looking for, is one of interest in what Cucumber, as a tool, adds to existing test frameworks.
The answer:
Cucumber adds an extra level of communication between you (the development team) and the management team. You are able to link test cases to scenarios that are now understandable by the business, which means that everybody is on the same page. You can even use the BDD tool to start talking about behaviours of the feature:
What things should be included?
Do we need more information?
Lets add that to the file, so that we can test that use case later.
Any new functionality added to the feature later?
Need to understand which section has gone wrong quickly, without having to decipher code written by the intern that was in for 2 months in the summer?
Cucumber helps with all of this, and that's just scraping the surface.
TestNG, JUnit, Selenium? You imagine it, you can do it. With Cucumber as your helpful neighbourhood BDD tool, you can pull together your test suite and bolt an abstraction layer on top. The business will now be able to look at the test results. Where tests have failed, they will be able to describe exactly what section has gone wrong to other members of management, without having to go too far into technical details.
If you're wondering whether to use JUnit or TestNG for this, it is most likely to be your choice. Using whatever is the current test tool to bolt cucumber on top of is the best option if you have an existing suite.
Also, make sure you are using the right language for your team. For instance:
Are you introducing a team of manual testers to developing test automation?
Maybe you should use Ruby or JavaScript, as they are easier languages to pick up as a first language
Are you a development team, using cucumber to add an abstraction layer to your unit tests?
Use the language that you are using for development, with the unit test tool that you are using.
Are you developers in test, using cucumber for automating tests for your website?
Use the language that you and your team are most comfortable with, taking the language being used for development over any others that tie with this (based on a team vote).

I think it depends on what are your other tests (unit ones for example) and how you run them.
If your current tests are already using TestNG, then it will be easier to run Cucumber tests with TestNG engine.
At the opposite, if you already have JUnit tests, it could be easier to use JUnit for Cucumber run (but TestNG is able to run JUnit tests, so you can use TestNG in that case too).
And if you have no other tests, so the choice of the test runner will depend on your own taste.

Yes.. I understand your question. Even I had the same doubt as below:
We use selenium for automation testing. Since they don't provide proper reports, we add TestNG to it (and also for other features). But now, we have cucumber, which gives proper reports. So why do we need TestNG?
I realized, though we get proper results with cucumber, TestNG provides us with many other features which cucumber cannot; like setting priority, setting method dependency, timeouts, grouping , etc.
Though cucumber provides a tag feature, it does not provide all the features provided by TestNG. Maybe when cucumber incorporates all those features, we can eliminate TestNG.

Related

Other than DSL what is the utility of Cucumber over TestNG and Junit and how to use #Test annotations with Gherkin's Given When Then annotation?

I've 2 questions.
I know Domain Specific Language could be used to write acceptance cases in cucumber but while implementing those steps #Given, #When ,#Then annotations are used in step definition then if one doesn't have to use dataprovider or grouping or parallel execution and run it using IDE then does TestNg or Junit would be required?
As #Test is generally used for a complete test scenario when only TestNg is used so when Cucumber is also used then is there a need to use #Test annotation if yes then how can it be used along with #Given, #When, #Then?
Ad 1.
The upside of using Gherkin is to have specifications that can also be read by non-programmers.
The upside of using Gherkin with Cucumber is that you can automate these specifications to have automated tests, or executable specifications.
Another upside of automating with Cucumber, is that steps are implemented to be reused which makes it easier to add similar test scenarios. (This reusability of steps is not the case with unit test tools, although one might argue they're easier to write anyway.)
The downside of having to implement the step definitions is having to implement the step definitions, which can take some time. And some developers consider this to be overly verbose. So I'd only do it if it brings added value in communicating with non-technical people.
Note 1: You will still need JUnit (or TestNg) as an assertion library.
Note 2: Cucumber by itself does not support parallel execution.
Ad 2.
You will not need to use #Test annotation with Cucumber

softassert/verify in Serenity with Jbehave BDD framework in Selenium

I am working in Automation project with Serenity/JBehave BDD framework and am facing the issue when any step fails in the story, the rest of the steps are not getting executed because of hardassert.
I want to know if there is any softassert like in TestNG or any verify option in Serenity/JBehave.
The best option for soft asserts at the moment is to use Serenity Screenplay (http://thucydides.info/docs/articles/soft-asserts.html), which provides a number of powerful options in this area. We may integrate soft asserts into the general #Step libraries at some point in the future.
This might be what your looking for:
embedderControls.doIgnoreFailureInStories(false);
embedderControls.doIgnoreFailureInView(false);
Only you'd want to change the first one, at least, to true.

How to run together Cucumber and Gatling

I am new to test and during my intership, I had to look for some good tools to automate functional tests.
So I made a lot of searches and decided to use Cucumber, linked with Selenium and SoapUI.
But the fact is that another search had been made before to automate load tests and Gatling (used with Jenkins) had been chosen for that.
Then I am asking to find a solution to gather the 2 solutions but it is quite hard to find any solution about that.
The only information I catch was using Taurus to have a single configuration file.
If you have any information which you think coul help me, I would be very thankful.
The purpose and techniques used by cucumber and gatling are very different so you will probably not want to push interoperation too far.
For example, you plan to use Selenium in your cucumber steps. That would not work well with the performance testing.
If you use jvm version of cucumber, you'll be able to reuse some of the utilities, for example test builders.

Automatic testing of web applications with Selenium

is there any tool out there that i can used to set-up run automatically and i was goggling and i found selenium test runner? there are so many tools out there its hard to figured out which is best
I'm using C# and using MSTest as a test framework and I'm looking forward to see if I can get a way from testing in MSTEST
any help?
This is very subjective question. Every requirement will have its own correct answer. Anyhow I will try to address few requirements and will be updating as I learn more.
If you are automating web app browser tests (sans flash player and silverlight) I would say that selenium is the way to go. There are ways to automate flash and silverlight too, but that is answer for another question.
Selenium is anyways an automation too and your choice will rather is of which test framework to select. So here are few options:
1. Integrating with CI tools:
If you want to organize your tests as segregated atomic units and want them to be integrated to some CI server (e.g. TeamCity). I will recommend using NUnit to run your selenium tests.
2. Behavioral Tests
It is a new trend in the software development and how we test our products. Using behavioral (i.e. business specification) like language. In my experience it is also a very good format to write up acceptance tests. You can use selenium with something like Nbehave or SpecFlow
3. Centralize Test management and Execution
Now this might not fit for everyone but I have found FitNesse (and its c# binding) to be very useful in maintaining and executing selenium test cases.
Please note this answer may not be right and is certainly not complete given the scope of the question. I have nevertheless tried provide few pointers.

Selenium tests: html vs code?

Is it better to write/record selenium tests in html format and run them directly in the server with "-htmlSuite" or to write the tests in java/C#/... and run them in the server using selenium-rc?
What is the recommended solution?
I would always recommend people writing their Selenium Tests in a programming language because it allows the tests to be a lot more expressive.
You can create common methods that all tests use and if that changes you can then update 1 method to get n tests passing because they all fail on that item. One example of this is the Page Object model which is a development method for tests that suggest you create a DSL for each page you interact with and then your tests read a lot more fluently to both technical and non-technical people.
If you write your tests in a programming language you can also take advantage of Selenium Grid which runs your tests in parallel to make them faster
I'd highly recommend you look at moving to Selenium in C#, Ruby,PHP or Python. I found many timing issues resolving once I got away from the HTML Selenese.
I might keep in mind how you plan on executing your recorded tests. For instance, it might be trivial to incorporate Selenium's generated JUnit tests into a pre-existing JUnit-based testing framework.