Cucumber Eclipse SetupCreate Eclipse Maven Project
import cucumber.api.junit.Cucumber;
import junit.framework.TestCase;
import cucumber.api.java.en.Then;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;public class StepDefinitions{
WebDriver driver = null;
@Given("^I will open the browser$")
public void openBrowser() {
System.setProperty("webdriver.chrome.driver", "chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
}
@When("^I will open Facebook website$")
public void goToFacebook() {
driver.navigate().to("https://www.facebook.com/");
}
@Then("^Login button should exists$")
public void loginButton() {
if(driver.findElement(By.id("u_0_v")).isEnabled()) {
System.out.println("Pass");
} else {
System.out.println("Fail");
}
driver.close();
}
}
Create CucumberRunner.java
- Open pom.xml
- Goto Dependencies
- Add GroupId: info.cukes, Artifact Id: cucumber-java, Version: 1.2.5
- Add GroupId: info.cukes, Artifact Id: cucumber-junit, Version: 1.2.5Create Features Folder and add StepDefinitions.feature file
Create a Feature File
- Feature: Login Feature
- Scenario: Verify Login Functionality
- Given I will open the browser
- When I will open Facebook website
- Then Login button should exists
import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;import cucumber.api.junit.Cucumber;
import junit.framework.TestCase;
import cucumber.api.java.en.Then;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;public class StepDefinitions{
WebDriver driver = null;
@Given("^I will open the browser$")
public void openBrowser() {
System.setProperty("webdriver.chrome.driver", "chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
}
@When("^I will open Facebook website$")
public void goToFacebook() {
driver.navigate().to("https://www.facebook.com/");
}
@Then("^Login button should exists$")
public void loginButton() {
if(driver.findElement(By.id("u_0_v")).isEnabled()) {
System.out.println("Pass");
} else {
System.out.println("Fail");
}
driver.close();
}
}
Create CucumberRunner.java
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;@RunWith(Cucumber.class)
@CucumberOptions(
features="Features"
)
public class CucumberRunner {}
import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;@RunWith(Cucumber.class)
@CucumberOptions(
features="Features"
)
public class CucumberRunner {}
No comments:
Post a Comment