-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathSampleSteps.java
More file actions
102 lines (83 loc) · 3.47 KB
/
Copy pathSampleSteps.java
File metadata and controls
102 lines (83 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package stepDefinitions;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class SampleSteps {
private WebDriver driver;
public SampleSteps() {
this.driver = Hooks.driver;
}
@Given("^I am on the home page$")
public void iAmOnTheHomePage() throws Throwable {
driver.get("https://kristinek.github.io/site");
}
@Then("^I should see home page header$")
public void iShouldSeeHomePageHeader() throws Throwable {
assertEquals("This is a home page",
driver.findElement(By.cssSelector("h1")).getText());
}
@And("^I should see home page description$")
public void iShouldSeeHomePageDescription() throws Throwable {
assertEquals("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
driver.findElement(By.cssSelector("p")).getText());
}
@When("^I enter name: \"([^\"]*)\"$")
public void iEnterName(String name) throws Throwable {
driver.findElement(By.id("name")).clear();
driver.findElement(By.id("name")).sendKeys(name);
}
@And("^I enter age: (\\d+)$")
public void iEnterAge(int age) throws Throwable {
driver.findElement(By.id("age")).sendKeys(String.valueOf(age));
}
@Given("^I (?:am on|open) age page$")
public void iAmOnAgePage() throws Throwable {
driver.get("https://kristinek.github.io/site/examples/age");
}
@And("^I click submit age$")
public void iClickSubmitAge() throws Throwable {
driver.findElement(By.id("submit")).click();
}
@Then("^I see message: \"([^\"]*)\"$")
public void iSeeMessage(String message) throws Throwable {
assertEquals(message, driver.findElement(By.id("message")).getText());
}
@When("^I enter values:$")
public void iEnterValues(Map<String, String> valuesToEnter) throws Throwable {
for (Map.Entry<String, String> e : valuesToEnter.entrySet()) {
driver.findElement(By.id(e.getKey())).clear();
driver.findElement(By.id(e.getKey())).sendKeys(e.getValue());
System.out.println("key is " + e.getKey());
System.out.println("value is " + e.getValue());
}
}
@And("^I should see menu$")
public void iShouldSeeMenu() throws Throwable {
assertTrue(driver.findElement(By.className("w3-navbar")).isDisplayed());
}
@And("^I click the result checkbox button$")
public void iClickTheResultCheckboxButton() throws Throwable {
driver.findElement(By.id("result_button_checkbox")).click();
}
@When("^I clicked on checkboxes:$")
public void iClickedOnCheckboxes(List<String> values) throws Throwable {
for (String value : values) {
driver.findElement(By.cssSelector("[value='" + value + "']")).click();
}
}
@Then("^message for checkboxes \"([^\"]*)\" is seen$")
public void messageForCheckboxesIsSeen(String message) throws Throwable {
assertEquals(message, driver.findElement(By.id("result_checkbox")).getText());
}
@Given("^I am on action page$")
public void iAmOnActionPage() {
driver.get("https://kristinek.github.io/site/examples/actions");
}
}