1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package dev.aherscu.qa.testing.example.scenarios.tutorial3;
18
19 import static dev.aherscu.qa.testing.utils.StreamMatchersExtensions.*;
20 import static dev.aherscu.qa.testing.utils.StringUtilsExtensions.*;
21 import static org.apache.commons.lang3.RandomStringUtils.*;
22 import static org.hamcrest.Matchers.*;
23 import static org.hamcrest.Matchers.equalTo;
24
25 import java.util.stream.*;
26
27 import org.hamcrest.*;
28 import org.testng.annotations.*;
29
30 import dev.aherscu.qa.jgiven.commons.model.*;
31 import dev.aherscu.qa.jgiven.commons.tags.*;
32 import dev.aherscu.qa.jgiven.webdriver.*;
33 import dev.aherscu.qa.testing.example.*;
34 import dev.aherscu.qa.testing.example.steps.tutorial.*;
35 import lombok.*;
36
37 public class TestingWebWithJGiven
38 extends ApplicationPerMethodWebSessionTest<TestConfiguration, GoogleFixtures<?>, GoogleActions<?>, GoogleVerifications<?>> {
39
40 protected TestingWebWithJGiven() {
41 super(TestConfiguration.class);
42 }
43
44 @DataProvider
45 private Object[][] data() {
46 return new Object[][] {
47 { new QuotedText(randomAlphanumeric(40)),
48 counts(equalTo(0L)) },
49 { new QuotedText("testng"),
50 anyMatch(containsStringIgnoringCase("testng")) }
51 };
52 }
53
54 @Reference("68")
55 @Test(dataProvider = INTERNAL_DATA_PROVIDER)
56 public void shouldFind(
57 final Text textToSearch,
58 final Matcher<Stream<String>> titleRule) {
59 given()
60 .google(webDriver.get());
61
62 when()
63 .searching_for(textToSearch);
64
65 then()
66 .the_results(
67 adaptedStream(googleResult -> googleResult.title.value,
68 titleRule));
69 }
70
71 @BeforeMethod
72 @SneakyThrows
73 @Override
74 public void beforeMethodOpenWebDriver() {
75 super.beforeMethodOpenWebDriver();
76 webDriver.get().asRemote().manage().window().maximize();
77 }
78
79 private static class QuotedText extends Text {
80 public QuotedText(final String value) {
81 super(wrap(value, DOUBLE_QUOTE));
82 }
83 }
84 }