Showing posts with label TestNG. Show all posts
Showing posts with label TestNG. Show all posts

Tuesday, March 21, 2023

CucumberRunner sample


In this example file, I've added the following options while extending the AbstractTestNGCucumberTests class

import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;

@CucumberOptions(
        features = "src/test/resources/features",
        glue = {"step_definitions"},
        tags = "@JREQ-BA001-2088 or @smoke or @SE",
        plugin = {
                "pretty",
                "html:target/cucumber-html-report",
                "json:target/cucumber.json",
                "rerun:target/rerun.txt"
        },
        strict = true,
        monochrome = true,
        dryRun = false,
        snippets = cucumber.api.SnippetType.CAMELCASE
)
public class MyTestRunner extends AbstractTestNGCucumberTests {
}

  • tags: Allows you to run only scenarios with specific tags. In this case, we're running scenarios with any of the three tags specified in the feature file. I have the story ticket, the test inclusion category and the feature tagged.
  • plugin: This specifies the output formats for the Cucumber report. In addition to the "pretty" format, we're also generating an HTML report, a JSON report, and a rerun file (which lists any scenarios that failed on the first run and need to be rerun).
  • strict: If set to true, Cucumber will fail if there are any undefined or pending steps. I prefer to have this set to false and user the power of the dryRun option.
  • monochrome: This makes the output in the console easier to read by removing colour and special characters.
  • dryRun: If set to true, Cucumber will check that all steps have corresponding step definitions, but won't actually run the scenarios. This can be useful for quickly checking that your step definitions match your feature file.
  • snippets: This specifies the naming convention for generated step definitions. In this case, we're using CamelCase naming.

Monday, December 12, 2022

Selenium - Configure TestNG to your Selenium framework.

To enable TestNG features in out test framework, as the first step we need to load the TestNG libraries to our test development environment(Eclipse).
  • Go to mvnreposotory.com and type in "testng"in the search bar. 
  • In the search results, select the latest available for dependency version. At the time of writing this blog I got below 7.6.1 version. 
  • Copy maven syntax for the dependency, so that we can paste it to our pom.xml. 
  • Once copied append it to the pom.xml of your maven project (which the framework was being built.
  • Accordingly I added below to my pom.xml.
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.6.1</version>
    <scope>test</scope>
</dependency>

Also we need to install the testNG plugin to the IDE. Go to Help >> Eclipse Market Place >> search for "TestNG"
Select to install the plugin and you are good.

Tuesday, November 15, 2022

Beginners Spot - Setup Maven in Test Automation environment

1)  Install Maven  (Windows)

  - Download from maven website and unzip the file.

  - Set MAVEN_HOME -  <base dire>\apache-maven-3.8.6

  - Add to path -  <base dire>\apache-maven-3.8.6\bin

2) Test the installation

 - Open cmd and type mvn --version

 - Should return maven home, version etc.

3) Create a maven project in Eclipse ( You can use maven-quickstart-archetype)

4) Integrate to Eclipse

 - Apply Maven Surefire plugin to Eclipse.

 -  Go to Maven Surefire plugin page >Usage (https://maven.apache.org/surefire/maven-surefire-plugin/usage.html)

 - Copy the plugin management snippet and paste in the pom.xml in your eclipse project.

  1. <build>
  2. <pluginManagement>
  3. <plugins>
  4. <plugin>
  5. <groupId>org.apache.maven.plugins</groupId>
  6. <artifactId>maven-surefire-plugin</artifactId>
  7. <version>3.0.0-M7</version>
  8. </plugin>
  9. </plugins>
  10. </pluginManagement>
  11. </build>

Paste this above your dependencies section in the pom.xml.

 - now you can run mvn clean, mvn test commands.

5) Integrate TestNG

 - We need to add an additional configuration to the plugins section in the pom.xml

 - Go to https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html

  1. <configuration>
  2. <suiteXmlFiles>
  3. <suiteXmlFile>testng.xml</suiteXmlFile>
  4. </suiteXmlFiles>
  5. </configuration>

- Also you need to add the TestNG dependency to the pom.xml, if its not already added.


Featured

Selenium - Page Object Model and Action Methods

  How we change this code to PageObjectModel and action classes. 1 2 3 driver . findElement ( By . id ( "userEmail" )). sendKeys (...

Popular Posts