Dry Run in Cucumber

HOME

import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;

@CucumberOptions(plugin = {"pretty"}, 
                 features = "src/test/resources/Features", 
                 glue = "org.example.stepdefinitions", 
                 monochrome=true,
                 dryRun = true)

public class CucumberRunnerTests extends AbstractTestNGCucumberTests {

}

Feature: Login to HRM Application

  @ValidCredentials
  Scenario: Login with valid credentials
   
   Given User is on HRMLogin page "https://opensource-demo.orangehrmlive.com/"
    When User enters username as "Admin" and password as "admin123"
    Then User should be able to login successfully and new page open

import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import java.time.Duration;

public class LoginPageDefinitions {
    
	private static WebDriver driver;
    public final static int TIMEOUT = 5;

     @Before
    public void setUp() {

        WebDriverManager.chromedriver().setup();
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--start-maximized");      
        driver = new ChromeDriver(options);
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(TIMEOUT));
    }


    @Given("User is on HRMLogin page {string}")
    public void loginTest(String url) {

        driver.get(url);

    }

    @When("User enters username as {string} and password as {string}")
    public void goToHomePage(String userName, String passWord) {

        // login to application
        driver.findElement(By.name("username")).sendKeys(userName);
        driver.findElement(By.name("password")).sendKeys(passWord);
        driver.findElement(By.xpath("//*[@id='app']/div[1]/div/div[1]/div/div[2]/div[2]/form/div[3]/button")).submit();

        // go the next page

    }

    @After
    public void teardown() {

        driver.quit();
    }

}

import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;

@CucumberOptions(plugin = {"pretty"}, 
                 features = "src/test/resources/Features", 
                 glue = "org.example.stepdefinitions", 
                 monochrome=true,
                 dryRun = false)

public class CucumberRunnerTests extends AbstractTestNGCucumberTests {

}

Leave a comment