Skip to content

Commit 66f9d7d

Browse files
committed
fixed images and checkbox scenario
1 parent ccccdd5 commit 66f9d7d

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
1-
package step_definition.templates.ui;public class BrokenImagesStepDefinition {
1+
package step_definition.templates.ui;
2+
3+
import io.cucumber.java.en.Then;
4+
import io.cucumber.java.en.When;
5+
import org.openqa.selenium.By;
6+
import org.openqa.selenium.WebElement;
7+
8+
import static modules.Hooks.driver;
9+
import static org.junit.Assert.assertTrue;
10+
import static utils.Images.*;
11+
12+
public class BrokenImagesStepDefinition {
13+
WebElement image;
14+
@When("image {int}")
15+
public void imageImageIndex(int index) {
16+
image = driver.findElement(By.cssSelector("#content > div > img:nth-child("+index+")"));
17+
}
18+
19+
@Then("if broken test should fail")
20+
public void ifBrokenTestShouldFail() {
21+
assertTrue(!isImageBroken(image));
22+
}
223
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,27 @@
1-
package step_definition.templates.ui;public class CheckboxesStepDefinition {
1+
package step_definition.templates.ui;
2+
3+
import io.cucumber.java.en.Then;
4+
import io.cucumber.java.en.When;
5+
import org.openqa.selenium.By;
6+
import org.openqa.selenium.WebElement;
7+
8+
import static modules.Hooks.driver;
9+
import static org.junit.Assert.*;
10+
11+
public class CheckboxesStepDefinition {
12+
WebElement checkbox;
13+
14+
@When("user checks box {int}")
15+
public void userChecksBox(int arg0) {
16+
checkbox = driver.findElement(By.cssSelector("#checkboxes > input[type=checkbox]:nth-child("+arg0+")"));
17+
if (!checkbox.isSelected()) {
18+
checkbox.click();
19+
}
20+
}
21+
22+
@Then("checkbox {int} is checked")
23+
public void checkboxIsChecked(int arg0) {
24+
checkbox = driver.findElement(By.cssSelector("#checkboxes > input[type=checkbox]:nth-child("+arg0+")"));
25+
assertTrue(checkbox.isSelected());
26+
}
227
}

Diff for: src/test/java/utils/Images.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1-
package utils;public class Images {
1+
package utils;
2+
3+
import org.openqa.selenium.WebElement;
4+
5+
public class Images {
6+
7+
public static boolean isImageBroken(WebElement image) {
8+
return image.getAttribute("naturalWidth").equals("0");
9+
}
210
}

0 commit comments

Comments
 (0)