View Javadoc
1   /*
2    * Copyright 2023 Adrian Herscu
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package dev.aherscu.qa.testing.example.scenarios.tutorial5;
18  
19  import static org.hamcrest.Matchers.*;
20  
21  import org.testng.annotations.*;
22  
23  import dev.aherscu.qa.jgiven.commons.utils.*;
24  import dev.aherscu.qa.jgiven.webdriver.*;
25  import dev.aherscu.qa.testing.example.*;
26  import dev.aherscu.qa.testing.example.model.tutorial.*;
27  import dev.aherscu.qa.testing.example.steps.tutorial.*;
28  import lombok.*;
29  import lombok.extern.slf4j.*;
30  
31  @Slf4j
32  public class TestingWindowsWithJGiven
33      extends ApplicationPerClassWebSessionTest<TestConfiguration, CalculatorFixtures<?>, CalculatorActions<?>, CalculatorVerifications<?>> {
34  
35      protected TestingWindowsWithJGiven() {
36          super(TestConfiguration.class);
37      }
38  
39      @DataProvider
40      static Object[][] data() {
41          return new Object[][] {
42              { Calculation.builder().expression("7+8").result("15").build() },
43              { Calculation.builder().expression("2*5").result("10").build() },
44              { Calculation.builder().expression("333/111").result("3").build() },
45              { Calculation.builder().expression("7-8").result("-1").build() },
46          };
47      }
48  
49      @BeforeClass
50      @SneakyThrows
51      @Override
52      protected void beforeClassOpenWebDriver() {
53          log.debug("before class opening WinAppDriver");
54          webDriver.set(WebDriverEx.from(configuration()
55              .capabilitiesFor("provider.local.windows")));
56      }
57  
58      @Test
59      public void shouldOpenCalculator() {
60          given()
61              .a_calculator(webDriver.get());
62  
63          then()
64              .the_title(is(equalTo("Calculator")));
65      }
66  
67      @Test(dataProvider = INTERNAL_DATA_PROVIDER)
68      public void shouldCalculate(final Calculation calculation) {
69          given()
70              .a_calculator(webDriver.get());
71  
72          when()
73              .typing(calculation.expression + "=");
74  
75          then()
76              .the_result(is(
77                  stringContainsInOrder("Display is", calculation.result)));
78      }
79  }