Wednesday, 30 May 2018


How to run Cucumber Feature file using Junit or TestNg



Run through Junit


@RunWith(Cucumber.class)
@CucumberOptions(
                  features = “src/test/Your features file“,
                  glues="src/test/Your Step Defnitio File"
                  tags ={“@SoapUI,@Functional"},...  )

public class TestRunnerClass
{
// You should keep empty

}

Run through TestNG

@CucumberOptions(
        format={"pretty","json:path/to/json_report.json"},
        features = "Path_to_Your_features_file",
        glue="Path_to_Your_stepDefinition file",
        tags={"@smoke,@regression")
        )

public class TestRunner extends AbstractTestNGCucumberTests

{
  //keep empty
}

Difference between Nunit and Xunit and MSTest

Attributes ( like Annotations in junit or TestNG)
NUnit 3.xMSTest 15.xxUnit.net 2.xComments
[Test][TestMethod][Fact]Marks a test method.
[TestFixture][TestClass]n/axUnit.net does not require an attribute for a test class; it looks for all test methods in all public (exported) classes in the assembly.
Assert.That
Record.Exception
[ExpectedException]Assert.Throws
Record.Exception
xUnit.net has done away with the ExpectedException attribute in favor of Assert.Throws. See Note 1
[SetUp][TestInitialize]ConstructorWe believe that use of [SetUp] is generally bad. However, you can implement a parameterless constructor as a direct replacement.
[TearDown][TestCleanup]IDisposable.DisposeWe believe that use of [TearDown] is generally bad. However, you can implement IDisposable.Disposeas a direct replacement.
[OneTimeSetUp][ClassInitialize]IClassFixture<T>To get per-class fixture setup, implement IClassFixture<T> on your test class.
[OneTimeTearDown][ClassCleanup]IClassFixture<T>To get per-class fixture teardown, implement IClassFixture<T> on your test class.
n/an/aICollectionFixture<T>To get per-collection fixture setup and teardown, implement ICollectionFixture<T> on your test collection.
[Ignore("reason")][Ignore][Fact(Skip="reason")]Set the Skip parameter on the [Fact] attribute to temporarily skip a test.
[Property][TestProperty][Trait]Set arbitrary metadata on a test
[Theory][DataSource][Theory]
[XxxData]
Theory (data-driven test).

Difference between Junit and TestNG

FeatureJUnit 4TestNG
test annotation@Test@Test
run before all tests in this suite have run—@BeforeSuite
run after all tests in this suite have run—@AfterSuite
run before the test—@BeforeTest
run after the test—@AfterTest
run before the first test method that belongs to any of these groups is invoked—@BeforeGroups
run after the last test method that belongs to any of these groups is invoked—@AfterGroups
run before the first test method in the current class is invoked@BeforeClass@BeforeClass
run after all the test methods in the current class have been run@AfterClass@AfterClass
run before each test method@Before@BeforeMethod
run after each test method@After@AfterMethod
ignore test@ignore@Test(enbale=false)
expected exception@Test(expected = ArithmeticException.class)@Test(expectedExceptions = ArithmeticException.class)
timeout@Test(timeout = 1000)@Test(timeout = 1000)

Selenium, C# with SpecFlow Setup requirement

1. Selenium WebDriver

Site : http://selenium-release.storage.googleapis.com/index.html?path=3.12/

File Name : selenium-dotnet-3.12.1.zip


2. Visual Studio

3. Nunit
       Go with Nunit 3 as it supports Parallel execution

      Site: http://nunit.org/download/

4. C# ( will be supported by Visual Studio by default)
5. Reporting ( NuGet Gallery | NUnitOrange 2.1.0)

It will covert TestResults.xml to Test Results.html

6. Building Tool ( MSbuild) - it is coming by default with OS
7. Jenkins ( https://jenkins.io)
8. Object Identification ( You can use Xpath and CSS, Please refer my previous post)
9. SpecFlow (BDD)
               Site : https://github.com/techtalk/SpecFlow/wiki/Advanced-Project-Setup










Selenium C# Automation Setup requirement

1. Selenium WebDriver

Site : http://selenium-release.storage.googleapis.com/index.html?path=3.12/

File Name : selenium-dotnet-3.12.1.zip


2. Visual Studio

3. Nunit
       Go with Nunit 3 as it supports Parallel execution

      Site: http://nunit.org/download/

4. C# ( will be supported by Visual Studio by default)
5. Reporting ( NuGet Gallery | NUnitOrange 2.1.0)

It will covert TestResults.xml to Test Results.html

6. Building Tool ( MSbuild) - it is coming by default with OS
7. Jenkins ( https://jenkins.io)
8. Object Identification ( You can use Xpath and CSS, Please refer my previous post)











Complete Xpath and CSS Guidance sheet:

www.cheat-sheets.org/saved-copy/Locators_table_1_0_2.pdf

Xpath and CSS Explanation

http://qavalidation.com/2015/05/xpath-css-patterns.html/

http://makeseleniumeasy.com/2018/04/09/writing-conditional-xpath-in-selenium-webdriver/