Skip to content

Commit 1bb67ce

Browse files
committed
added cucumber tests
1 parent 6449116 commit 1bb67ce

4 files changed

Lines changed: 103 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package StepDefinitions;
2+
3+
import io.cucumber.java.en.Given;
4+
import io.cucumber.java.en.Then;
5+
import io.cucumber.java.en.When;
6+
import org.openqa.selenium.By;
7+
import org.openqa.selenium.Keys;
8+
import org.openqa.selenium.WebDriver;
9+
import org.openqa.selenium.chrome.ChromeDriver;
10+
import java.util.concurrent.TimeUnit;
11+
12+
public class GoogleSearchSteps {
13+
14+
WebDriver driver = null;
15+
16+
@Given("User is on Google Search Page")
17+
public void user_is_on_google_search_page() {
18+
System.out.println("Opening Browser...");
19+
System.out.println("Project Path: " + System.getProperty("user.dir"));
20+
//driver setup
21+
driver = new ChromeDriver(); // assumes chrome driver is setup and is in Path var
22+
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
23+
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
24+
driver.manage().window().maximize();
25+
26+
driver.get("http://www.google.com");
27+
System.out.println("User is on search page");
28+
}
29+
30+
// example of passing search term using parameter with regex
31+
@When("^I enter (.*) in box$")
32+
public void i_enter_search_term_in_box(String searchterm) {
33+
34+
driver.findElement(By.name("q")).sendKeys(searchterm);
35+
36+
}
37+
38+
@When("I click on Search button")
39+
public void i_click_on_search_button() {
40+
41+
driver.findElement(By.name("q")).sendKeys(Keys.ENTER);
42+
43+
}
44+
45+
@Then("Show Results")
46+
public void show_results() throws InterruptedException {
47+
System.out.println("Showing results");
48+
49+
Thread.sleep(2);
50+
driver.close();
51+
driver.quit();
52+
System.out.println("Closed Browser");
53+
}
54+
55+
56+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package StepDefinitions;
2+
3+
import org.junit.runner.RunWith;
4+
5+
import io.cucumber.junit.CucumberOptions;
6+
import io.cucumber.junit.Cucumber;
7+
8+
@RunWith(Cucumber.class)
9+
@CucumberOptions(
10+
features = "src/test/resources/Features",
11+
glue = {"StepDefinitions"},
12+
monochrome = true,
13+
//plug-in = {"pretty", "html:target/HtmlReports/test_report.html"}, // HTML report
14+
//plugin = {"pretty", "json:target/JSONReports/test_report.json"} // JSON report
15+
//plugin = {"pretty", "junit:target/XMLReports/test_report.xml"} // junit xml report
16+
plugin = {"pretty",
17+
"html:target/HtmlReports/test_report.html",
18+
"json:target/cucumber.json", // needs to under target folder for maven-cucumber-reporting to work
19+
"junit:target/XMLReports/test_report.xml"
20+
})
21+
public class TestRunner {
22+
}

src/test/java/com/example/JavaSpringBoot/WebTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
import org.junit.jupiter.api.AfterEach;
44
import org.junit.jupiter.api.BeforeEach;
55
import org.junit.jupiter.api.Test;
6+
import org.openqa.selenium.WebDriver;
7+
import org.openqa.selenium.chrome.ChromeDriver;
68
import org.springframework.boot.test.context.SpringBootTest;
79

10+
import java.util.concurrent.TimeUnit;
11+
812
import static org.junit.jupiter.api.Assertions.assertEquals;
913

1014
//@SpringBootTest, which will make the test a Spring Boot-driven test. This means that the test context
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Feature: To Test Google Search
2+
# Tests the Google Search Feature
3+
4+
# simple format
5+
Scenario: Test Google Search
6+
Given User is on Google Search Page
7+
When I enter Google in box
8+
And I click on Search button
9+
Then Show Results
10+
11+
# data table example
12+
Scenario Outline: Test Google Search using data tables
13+
Given User is on Google Search Page
14+
When I enter <search_term> in box
15+
And I click on Search button
16+
Then Show Results
17+
18+
Examples:
19+
| search_term|
20+
| cucumber |
21+
| java |

0 commit comments

Comments
 (0)