STEP 1: Install Java
STEP 2: Configure variable environment
a) Set the Java Home
b) Update PATH
STEP 3: Install Maven


STEP 1: Install Java



Go to
https://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html

Click Download


Accept License Agreement

STEP 2: Configure variable environment

a) Set the Java Home:

b) Update PATH

STEP 3: Install Maven

STEP 4: Install IntelliJ

STEP 5: Configure IntelliJ

STEP 6: Add Cucumber as Plugin

STEP 7: Setup Default SDK for Projects

STEP 8: Create New Project

or

Step 9: Update pom.xml

In the POM file, Replace this snippet:

<version>1.0-SNAPSHOT</version>
</project>

With:

<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.8</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>3.8.0</version>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.11.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>3.11.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.11.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.11.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.6-jre</version>
<classifier></classifier>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>

<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>3.8.0</version>

<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>

<configuration>
<projectName>UITest4</projectName> <!-- Replace with project name -->
<outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory>
<cucumberOutput>target/cucumber-reports/CucumberTestReport.json</cucumberOutput>
<buildNumber>1</buildNumber>
<parallelTesting>false</parallelTesting>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>



Step 10: Create Folder Structure

Create a folder under src/test /java

Right Java under src/Test

Click New

Click on Package


Create a resource directory

Right Click the Test on src/test

Click New

Click Directory

Enter “resources” as directory name

Make the resource folder your

Create Feature Folder

Step 11: Create TestRunner

Click Enter

TestRunner.cs

import cucumber.api.CucumberOptions;

import cucumber.api.testng.TestNGCucumberRunner;

import cucumber.api.testng.CucumberFeatureWrapper;

import org.testng.annotations.AfterClass;

import org.testng.annotations.BeforeClass;

import org.testng.annotations.DataProvider;

import org.testng.annotations.Test;

@CucumberOptions(

features = "src/test/resources/features",

glue = {"stepdefs"},

tags = {"~@Ignore"},

format = {

"pretty",

"html:target/cucumber-reports/cucumber-pretty",

"json:target/cucumber-reports/CucumberTestReport.json",

"rerun:target/cucumber-reports/rerun.txt"

})

public class TestRunner {

private TestNGCucumberRunner testNGCucumberRunner;

@BeforeClass(alwaysRun = true)

public void setUpClass() throws Exception {

testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());

}

@Test(groups = "cucumber", description = "Runs Cucumber Feature", dataProvider = "features")

public void feature(CucumberFeatureWrapper cucumberFeature) {

testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());

}

@DataProvider

public Object[][] features() {

return testNGCucumberRunner.provideFeatures();

}

@AfterClass(alwaysRun = true)

public void tearDownClass() throws Exception {

testNGCucumberRunner.finish();

}

}

Step 12: Create testng.xml

Create testng.xml:

Under your Project create a file called testng.xml

Copy the content below:

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd”>

<suite name=”BDD Test Suite” verbose=”1″ parallel=”tests” thread-count=”1″ configfailurepolicy=”continue”>

<test name=”Login and Update Profile Test” annotations=”JDK” preserve-order=”true”>

<classes>

<class name=”TestRunner”/>

</classes>

</test>

</suite>

Step 12: Create Feature File

 

 

Feature File

Login.Feature

Scenario: Valid Login
Given I navigate to blueskycitadel site
And I click on login link
When I enter username
And I enter password
And I click on login button
Then I am logged in




Feature: BlueSky Form Test
Scenario: Form Test
Given I navigate to blueskycitadelform site
When I enter first name
And I enter Lastname
And I send age 18-30
And I click on Submit
Then the form is submitted


Step Definition

package stepdefs;

import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class BlueSkyFormStep
{

//STEP 1: declare webdriver
WebDriver driver;

@Given("^I navigate to blueskycitadelform site$")
public void iNavigateToBlueskycitadelformSite()
{
//STEP 2: set your system path
System.setProperty("webdriver.gecko.driver", "D:\\BlueskyCitadel\\firefox\\geckodriver.exe");

//STEP 3: Instantiate your firefox driver
driver = new FirefoxDriver();

//STEP 4: Navigate to url
driver.get("http://blueskycitadel.com/test-form-for-bluesky-automation-training/");

}


@When("^I enter first name$")
public void i_enter_first_name() throws Throwable
{
//STEP 5a: Get your element
//STEP 5b: Send key to the element
driver.findElement(By.id("nf-field-26")).sendKeys("Deji");
}

@When("^I enter Lastname$")public void i_enter_Lastname() throws Throwable
{
driver.findElement(By.cssSelector("#nf-field-27")).sendKeys("Ogunlaja");
}

@When("^I send age (\\d+)-(\\d+)$")
public void i_send_age(int arg1, int arg2) throws Throwable
{
driver.findElement(By.xpath("//*[@id=\"nf-field-31-0\"]")).click();
}

@When("^I click on Submit$")
public void i_click_on_Submit() throws Throwable
{
driver.findElement(By.id("nf-field-37")).click();
}

@Then("^the form is submitted$")
public void the_form_is_submitted() throws Throwable
{
// Write code here that turns the phrase above into concrete actions
//STEP 5: assert that the form is submitted


}


}
  • Share :
Blue Sky Citadel