17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/1-optimize-refactor-flaky-tests/src/main/java/decorators/Browser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package decorators;
15 |
16 | public enum Browser {
17 | CHROME,
18 | FIREFOX,
19 | EDGE,
20 | OPERA,
21 | SAFARI,
22 | INTERNET_EXPLORER
23 | }
24 |
--------------------------------------------------------------------------------
/1-optimize-refactor-flaky-tests/src/main/java/decorators/Driver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package decorators;
15 |
16 | import org.openqa.selenium.By;
17 | import java.util.List;
18 |
19 | public abstract class Driver {
20 | public abstract void start(Browser browser);
21 | public abstract void quit();
22 | public abstract void goToUrl(String url);
23 | public abstract Element findElement(By locator);
24 | public abstract List findElements(By locator);
25 | }
26 |
--------------------------------------------------------------------------------
/1-optimize-refactor-flaky-tests/src/main/java/decorators/DriverDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package decorators;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | import java.util.List;
19 |
20 | public class DriverDecorator extends Driver {
21 | protected final Driver driver;
22 |
23 | public DriverDecorator(Driver driver) {
24 | this.driver = driver;
25 | }
26 |
27 | @Override
28 | public void start(Browser browser) {
29 | driver.start(browser);
30 | }
31 |
32 | @Override
33 | public void quit() {
34 | driver.quit();
35 | }
36 |
37 | @Override
38 | public void goToUrl(String url) {
39 | driver.goToUrl(url);
40 | }
41 |
42 | @Override
43 | public Element findElement(By locator) {
44 | return driver.findElement(locator);
45 | }
46 |
47 | @Override
48 | public List findElements(By locator) {
49 | return driver.findElements(locator);
50 | }
51 | }
--------------------------------------------------------------------------------
/1-optimize-refactor-flaky-tests/src/main/java/decorators/Element.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package decorators;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | public abstract class Element {
19 | public abstract By getBy();
20 | public abstract String getText();
21 | public abstract Boolean isEnabled();
22 | public abstract Boolean isDisplayed();
23 | public abstract void typeText(String text) throws InterruptedException;
24 | public abstract void click();
25 | public abstract String getAttribute(String attributeName);
26 | }
27 |
--------------------------------------------------------------------------------
/1-optimize-refactor-flaky-tests/src/main/java/decorators/ElementDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package decorators;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | public class ElementDecorator extends Element {
19 | protected final Element element;
20 |
21 | protected ElementDecorator(Element element) {
22 | this.element = element;
23 | }
24 |
25 | @Override
26 | public By getBy() {
27 | return element.getBy();
28 | }
29 |
30 | @Override
31 | public String getText() {
32 | return element.getText();
33 | }
34 |
35 | @Override
36 | public Boolean isEnabled() {
37 | return element.isEnabled();
38 | }
39 |
40 | @Override
41 | public Boolean isDisplayed() {
42 | return element.isDisplayed();
43 | }
44 |
45 | @Override
46 | public void typeText(String text) throws InterruptedException {
47 | element.typeText(text);
48 | }
49 |
50 | @Override
51 | public void click() {
52 | element.click();
53 | }
54 |
55 | @Override
56 | public String getAttribute(String attributeName) {
57 | return element.getAttribute(attributeName);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/1-optimize-refactor-flaky-tests/src/main/resources/chromedriver.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AutomateThePlanet/Design-Patterns-for-High-Quality-Automated-Tests-Java-Workshop/1eca774574a4ee67b170ec105bb040116f603193/1-optimize-refactor-flaky-tests/src/main/resources/chromedriver.exe
--------------------------------------------------------------------------------
/1-optimize-refactor-flaky-tests/src/test/exercises.txt:
--------------------------------------------------------------------------------
1 | Exercise 1: Implement same tests in WebDriverWaitProductPurchaseTests class using waitAndFindElement and waitToBeClickable methods
2 | Exercise 2: Implement same tests in DecoratorsProductPurchaseTests class using LoggingDriver
--------------------------------------------------------------------------------
/1-optimize-refactor-flaky-tests/src/test/java/decorators/DecoratorsProductPurchaseTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package decorators;
15 |
16 | import org.openqa.selenium.By;
17 | import org.testng.Assert;
18 | import org.testng.annotations.*;
19 |
20 | import java.util.UUID;
21 |
22 | public class DecoratorsProductPurchaseTests {
23 | private Driver driver;
24 | private static String purchaseEmail;
25 | private static String purchaseOrderNumber;
26 |
27 | @BeforeMethod
28 | public void testInit() {
29 | driver = new LoggingDriver(new WebCoreDriver());
30 | driver.start(Browser.CHROME);
31 | }
32 |
33 | @AfterMethod
34 | public void testCleanup() throws InterruptedException {
35 | driver.quit();
36 | }
37 |
38 | private String GetUserPasswordFromDb(String userName)
39 | {
40 | return "@purISQzt%%DYBnLCIhaoG6$";
41 | }
42 |
43 | private String generateUniqueEmail() {
44 | return String.format("%s@berlinspaceflowers.com", UUID.randomUUID().toString());
45 | }
46 | }
--------------------------------------------------------------------------------
/1-optimize-refactor-flaky-tests/target/classes/chromedriver.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AutomateThePlanet/Design-Patterns-for-High-Quality-Automated-Tests-Java-Workshop/1eca774574a4ee67b170ec105bb040116f603193/1-optimize-refactor-flaky-tests/target/classes/chromedriver.exe
--------------------------------------------------------------------------------
/2-speeding-up-tests/Chapter 3- Optimize the Tests.iml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/instrumentedcode/Browser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package instrumentedcode;
15 |
16 | public enum Browser {
17 | CHROME,
18 | FIREFOX,
19 | EDGE,
20 | OPERA,
21 | SAFARI,
22 | INTERNET_EXPLORER
23 | }
24 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/instrumentedcode/Driver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package instrumentedcode;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | import java.util.List;
19 |
20 | public abstract class Driver {
21 | public abstract void start(Browser browser);
22 |
23 | public abstract void quit();
24 |
25 | public abstract void goToUrl(String url);
26 |
27 | public abstract Element findElement(By locator);
28 |
29 | public abstract List findElements(By locator);
30 | }
31 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/instrumentedcode/DriverDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package instrumentedcode;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | import java.util.List;
19 |
20 | public class DriverDecorator extends Driver {
21 | protected final Driver driver;
22 |
23 | public DriverDecorator(Driver driver) {
24 | this.driver = driver;
25 | }
26 |
27 | @Override
28 | public void start(Browser browser) {
29 | driver.start(browser);
30 | }
31 |
32 | @Override
33 | public void quit() {
34 | driver.quit();
35 | }
36 |
37 | @Override
38 | public void goToUrl(String url) {
39 | driver.goToUrl(url);
40 | }
41 |
42 | @Override
43 | public Element findElement(By locator) {
44 | return driver.findElement(locator);
45 | }
46 |
47 | @Override
48 | public List findElements(By locator) {
49 | return driver.findElements(locator);
50 | }
51 | }
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/instrumentedcode/Element.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package instrumentedcode;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | public abstract class Element {
19 | public abstract By getBy();
20 |
21 | public abstract String getText();
22 |
23 | public abstract Boolean isEnabled();
24 |
25 | public abstract Boolean isDisplayed();
26 |
27 | public abstract void typeText(String text) throws InterruptedException;
28 |
29 | public abstract void click();
30 |
31 | public abstract String getAttribute(String attributeName);
32 | }
33 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/instrumentedcode/ElementDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package instrumentedcode;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | public class ElementDecorator extends Element {
19 | protected final Element element;
20 |
21 | protected ElementDecorator(Element element) {
22 | this.element = element;
23 | }
24 |
25 | @Override
26 | public By getBy() {
27 | return element.getBy();
28 | }
29 |
30 | @Override
31 | public String getText() {
32 | return element.getText();
33 | }
34 |
35 | @Override
36 | public Boolean isEnabled() {
37 | return element.isEnabled();
38 | }
39 |
40 | @Override
41 | public Boolean isDisplayed() {
42 | return element.isDisplayed();
43 | }
44 |
45 | @Override
46 | public void typeText(String text) throws InterruptedException {
47 | element.typeText(text);
48 | }
49 |
50 | @Override
51 | public void click() {
52 | element.click();
53 | }
54 |
55 | @Override
56 | public String getAttribute(String attributeName) {
57 | return element.getAttribute(attributeName);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowser/Browser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowser;
15 |
16 | public enum Browser {
17 | NOT_SET,
18 | CHROME,
19 | FIREFOX,
20 | EDGE,
21 | OPERA,
22 | SAFARI,
23 | INTERNET_EXPLORER
24 | }
25 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowser/Driver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowser;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | import java.util.List;
19 |
20 | public abstract class Driver {
21 | public abstract void start(Browser browser);
22 |
23 | public abstract void quit();
24 |
25 | public abstract void goToUrl(String url);
26 |
27 | public abstract Element findElement(By locator);
28 |
29 | public abstract List findElements(By locator);
30 |
31 | public abstract void waitForAjax();
32 |
33 | public abstract void waitUntilPageLoadsCompletely();
34 | }
35 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowser/DriverDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowser;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | import java.util.List;
19 |
20 | public class DriverDecorator extends Driver {
21 | protected final Driver driver;
22 |
23 | public DriverDecorator(Driver driver) {
24 | this.driver = driver;
25 | }
26 |
27 | @Override
28 | public void start(Browser browser) {
29 | driver.start(browser);
30 | }
31 |
32 | @Override
33 | public void quit() {
34 | driver.quit();
35 | }
36 |
37 | @Override
38 | public void goToUrl(String url) {
39 | driver.goToUrl(url);
40 | }
41 |
42 | @Override
43 | public Element findElement(By locator) {
44 | return driver.findElement(locator);
45 | }
46 |
47 | @Override
48 | public List findElements(By locator) {
49 | return driver.findElements(locator);
50 | }
51 |
52 | @Override
53 | public void waitForAjax() {
54 | driver.waitForAjax();
55 | }
56 |
57 | @Override
58 | public void waitUntilPageLoadsCompletely() {
59 | driver.waitUntilPageLoadsCompletely();
60 | }
61 | }
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowser/Element.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowser;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | public abstract class Element {
19 | public abstract By getBy();
20 |
21 | public abstract String getText();
22 |
23 | public abstract Boolean isEnabled();
24 |
25 | public abstract Boolean isDisplayed();
26 |
27 | public abstract void typeText(String text) throws InterruptedException;
28 |
29 | public abstract void click();
30 |
31 | public abstract String getAttribute(String attributeName);
32 | }
33 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowser/ElementDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowser;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | public class ElementDecorator extends Element {
19 | protected final Element element;
20 |
21 | protected ElementDecorator(Element element) {
22 | this.element = element;
23 | }
24 |
25 | @Override
26 | public By getBy() {
27 | return element.getBy();
28 | }
29 |
30 | @Override
31 | public String getText() {
32 | return element.getText();
33 | }
34 |
35 | @Override
36 | public Boolean isEnabled() {
37 | return element.isEnabled();
38 | }
39 |
40 | @Override
41 | public Boolean isDisplayed() {
42 | return element.isDisplayed();
43 | }
44 |
45 | @Override
46 | public void typeText(String text) throws InterruptedException {
47 | element.typeText(text);
48 | }
49 |
50 | @Override
51 | public void click() {
52 | element.click();
53 | }
54 |
55 | @Override
56 | public String getAttribute(String attributeName) {
57 | return element.getAttribute(attributeName);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowser/browserinfrastructure/BaseTestBehaviorObserver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowser.browserinfrastructure;
15 |
16 | import org.testng.ITestResult;
17 |
18 | import java.lang.reflect.Method;
19 |
20 | public class BaseTestBehaviorObserver implements TestBehaviorObserver {
21 | public BaseTestBehaviorObserver(TestExecutionSubject testExecutionSubject) {
22 | testExecutionSubject.attach(this);
23 | }
24 |
25 | @Override
26 | public void preTestInit(ITestResult testResult, Method memberInfo) {
27 | }
28 |
29 | @Override
30 | public void postTestInit(ITestResult testResult, Method memberInfo) {
31 | }
32 |
33 | @Override
34 | public void preTestCleanup(ITestResult testResult, Method memberInfo) {
35 | }
36 |
37 | @Override
38 | public void postTestCleanup(ITestResult testResult, Method memberInfo) {
39 | }
40 |
41 | @Override
42 | public void testInstantiated(Method memberInfo) {
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowser/browserinfrastructure/BrowserBehavior.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowser.browserinfrastructure;
15 |
16 | public enum BrowserBehavior {
17 | NOT_SET,
18 | REUSE_IF_STARTED,
19 | RESTART_EVERY_TIME,
20 | RESTART_ON_FAIL,
21 | }
22 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowser/browserinfrastructure/BrowserConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowser.browserinfrastructure;
15 |
16 | import reusebrowser.Browser;
17 |
18 | public class BrowserConfiguration {
19 | private Browser browser;
20 | private BrowserBehavior browserBehavior;
21 |
22 | public BrowserConfiguration(Browser browser, BrowserBehavior browserBehavior) {
23 | this.browser = browser;
24 | this.browserBehavior = browserBehavior;
25 | }
26 |
27 | public BrowserBehavior getBrowserBehavior() {
28 | return browserBehavior;
29 | }
30 |
31 | public void setBrowserBehavior(BrowserBehavior _browserBehavior) {
32 | this.browserBehavior = _browserBehavior;
33 | }
34 |
35 | public Browser getBrowser() {
36 | return browser;
37 | }
38 |
39 | public void setBrowser(Browser _browser) {
40 | this.browser = _browser;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowser/browserinfrastructure/ExecutionBrowser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowser.browserinfrastructure;
15 |
16 | import reusebrowser.Browser;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | @Target({ElementType.TYPE, ElementType.METHOD})
24 | @Retention(RetentionPolicy.RUNTIME)
25 | public @interface ExecutionBrowser {
26 | Browser browser() default Browser.CHROME;
27 |
28 | BrowserBehavior browserBehavior() default BrowserBehavior.RESTART_EVERY_TIME;
29 | }
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowser/browserinfrastructure/TestBehaviorObserver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowser.browserinfrastructure;
15 |
16 | import org.testng.ITestResult;
17 |
18 | import java.lang.reflect.Method;
19 |
20 | public interface TestBehaviorObserver {
21 | void preTestInit(ITestResult testResult, Method memberInfo);
22 |
23 | void postTestInit(ITestResult testResult, Method memberInfo);
24 |
25 | void preTestCleanup(ITestResult testResult, Method memberInfo);
26 |
27 | void postTestCleanup(ITestResult testResult, Method memberInfo);
28 |
29 | void testInstantiated(Method memberInfo);
30 | }
31 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowser/browserinfrastructure/TestExecutionSubject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowser.browserinfrastructure;
15 |
16 | import org.testng.ITestResult;
17 |
18 | import java.lang.reflect.Method;
19 |
20 | public interface TestExecutionSubject {
21 | void attach(TestBehaviorObserver observer);
22 |
23 | void detach(TestBehaviorObserver observer);
24 |
25 | void preTestInit(ITestResult result, Method memberInfo);
26 |
27 | void postTestInit(ITestResult result, Method memberInfo);
28 |
29 | void preTestCleanup(ITestResult result, Method memberInfo);
30 |
31 | void postTestCleanup(ITestResult result, Method memberInfo);
32 |
33 | void testInstantiated(Method memberInfo);
34 | }
35 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowsercleansession/Browser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowsercleansession;
15 |
16 | public enum Browser {
17 | NOT_SET,
18 | CHROME,
19 | FIREFOX,
20 | EDGE,
21 | OPERA,
22 | SAFARI,
23 | INTERNET_EXPLORER
24 | }
25 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowsercleansession/Driver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowsercleansession;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | import java.util.List;
19 |
20 | public abstract class Driver {
21 | public abstract void start(Browser browser);
22 |
23 | public abstract void quit();
24 |
25 | public abstract void goToUrl(String url);
26 |
27 | public abstract Element findElement(By locator);
28 |
29 | public abstract List findElements(By locator);
30 |
31 | public abstract void waitForAjax();
32 |
33 | public abstract void waitUntilPageLoadsCompletely();
34 |
35 | public abstract void deleteAllCookies();
36 | }
37 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowsercleansession/Element.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowsercleansession;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | public abstract class Element {
19 | public abstract By getBy();
20 |
21 | public abstract String getText();
22 |
23 | public abstract Boolean isEnabled();
24 |
25 | public abstract Boolean isDisplayed();
26 |
27 | public abstract void typeText(String text) throws InterruptedException;
28 |
29 | public abstract void click();
30 |
31 | public abstract String getAttribute(String attributeName);
32 | }
33 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowsercleansession/browserinfrastructure/BaseTestBehaviorObserver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowsercleansession.browserinfrastructure;
15 |
16 | import org.testng.ITestResult;
17 |
18 | import java.lang.reflect.Method;
19 |
20 | public class BaseTestBehaviorObserver implements TestBehaviorObserver {
21 | public BaseTestBehaviorObserver(TestExecutionSubject testExecutionSubject) {
22 | testExecutionSubject.attach(this);
23 | }
24 |
25 | @Override
26 | public void preTestInit(ITestResult testResult, Method memberInfo) {
27 | }
28 |
29 | @Override
30 | public void postTestInit(ITestResult testResult, Method memberInfo) {
31 | }
32 |
33 | @Override
34 | public void preTestCleanup(ITestResult testResult, Method memberInfo) {
35 | }
36 |
37 | @Override
38 | public void postTestCleanup(ITestResult testResult, Method memberInfo) {
39 | }
40 |
41 | @Override
42 | public void testInstantiated(Method memberInfo) {
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowsercleansession/browserinfrastructure/BrowserBehavior.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowsercleansession.browserinfrastructure;
15 |
16 | public enum BrowserBehavior {
17 | NOT_SET,
18 | REUSE_IF_STARTED,
19 | RESTART_EVERY_TIME,
20 | RESTART_ON_FAIL
21 | }
22 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowsercleansession/browserinfrastructure/BrowserConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowsercleansession.browserinfrastructure;
15 |
16 | import reusebrowsercleansession.Browser;
17 |
18 | public class BrowserConfiguration {
19 | private Browser browser;
20 | private BrowserBehavior browserBehavior;
21 |
22 | public BrowserConfiguration(Browser browser, BrowserBehavior browserBehavior) {
23 | this.browser = browser;
24 | this.browserBehavior = browserBehavior;
25 | }
26 |
27 | public BrowserBehavior getBrowserBehavior() {
28 | return browserBehavior;
29 | }
30 |
31 | public void setBrowserBehavior(BrowserBehavior _browserBehavior) {
32 | this.browserBehavior = _browserBehavior;
33 | }
34 |
35 | public Browser getBrowser() {
36 | return browser;
37 | }
38 |
39 | public void setBrowser(Browser _browser) {
40 | this.browser = _browser;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowsercleansession/browserinfrastructure/ExecutionBrowser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowsercleansession.browserinfrastructure;
15 |
16 | import reusebrowsercleansession.Browser;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | @Target({ElementType.TYPE, ElementType.METHOD})
24 | @Retention(RetentionPolicy.RUNTIME)
25 | public @interface ExecutionBrowser {
26 | Browser browser() default Browser.CHROME;
27 |
28 | BrowserBehavior browserBehavior() default BrowserBehavior.RESTART_EVERY_TIME;
29 | }
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowsercleansession/browserinfrastructure/TestBehaviorObserver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowsercleansession.browserinfrastructure;
15 |
16 | import org.testng.ITestResult;
17 |
18 | import java.lang.reflect.Method;
19 |
20 | public interface TestBehaviorObserver {
21 | void preTestInit(ITestResult testResult, Method memberInfo);
22 |
23 | void postTestInit(ITestResult testResult, Method memberInfo);
24 |
25 | void preTestCleanup(ITestResult testResult, Method memberInfo);
26 |
27 | void postTestCleanup(ITestResult testResult, Method memberInfo);
28 |
29 | void testInstantiated(Method memberInfo);
30 | }
31 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/reusebrowsercleansession/browserinfrastructure/TestExecutionSubject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package reusebrowsercleansession.browserinfrastructure;
15 |
16 | import org.testng.ITestResult;
17 |
18 | import java.lang.reflect.Method;
19 |
20 | public interface TestExecutionSubject {
21 | void attach(TestBehaviorObserver observer);
22 |
23 | void detach(TestBehaviorObserver observer);
24 |
25 | void preTestInit(ITestResult result, Method memberInfo);
26 |
27 | void postTestInit(ITestResult result, Method memberInfo);
28 |
29 | void preTestCleanup(ITestResult result, Method memberInfo);
30 |
31 | void postTestCleanup(ITestResult result, Method memberInfo);
32 |
33 | void testInstantiated(Method memberInfo);
34 | }
35 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/waitforajax/Browser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package waitforajax;
15 |
16 | public enum Browser {
17 | CHROME,
18 | FIREFOX,
19 | EDGE,
20 | OPERA,
21 | SAFARI,
22 | INTERNET_EXPLORER
23 | }
24 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/waitforajax/Driver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package waitforajax;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | import java.util.List;
19 |
20 | public abstract class Driver {
21 | public abstract void start(Browser browser);
22 |
23 | public abstract void quit();
24 |
25 | public abstract void goToUrl(String url);
26 |
27 | public abstract Element findElement(By locator);
28 |
29 | public abstract List findElements(By locator);
30 |
31 | public abstract void waitForAjax();
32 |
33 | public abstract void waitUntilPageLoadsCompletely();
34 | }
35 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/waitforajax/Element.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package waitforajax;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | public abstract class Element {
19 | public abstract By getBy();
20 |
21 | public abstract String getText();
22 |
23 | public abstract Boolean isEnabled();
24 |
25 | public abstract Boolean isDisplayed();
26 |
27 | public abstract void typeText(String text) throws InterruptedException;
28 |
29 | public abstract void click();
30 |
31 | public abstract String getAttribute(String attributeName);
32 | }
33 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/main/java/waitforajax/ElementDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package waitforajax;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | public class ElementDecorator extends Element {
19 | protected final Element element;
20 |
21 | protected ElementDecorator(Element element) {
22 | this.element = element;
23 | }
24 |
25 | @Override
26 | public By getBy() {
27 | return element.getBy();
28 | }
29 |
30 | @Override
31 | public String getText() {
32 | return element.getText();
33 | }
34 |
35 | @Override
36 | public Boolean isEnabled() {
37 | return element.isEnabled();
38 | }
39 |
40 | @Override
41 | public Boolean isDisplayed() {
42 | return element.isDisplayed();
43 | }
44 |
45 | @Override
46 | public void typeText(String text) throws InterruptedException {
47 | element.typeText(text);
48 | }
49 |
50 | @Override
51 | public void click() {
52 | element.click();
53 | }
54 |
55 | @Override
56 | public String getAttribute(String attributeName) {
57 | return element.getAttribute(attributeName);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/test/java/exercises.txt:
--------------------------------------------------------------------------------
1 | Exercise 1: Implement same tests in WaitForAjaxProductPurchaseTests class using new waitForAjax and waitUntilPageLoadsCompletely methods
2 | Exercise 2: Upgrade the tests in WaitForAjaxProductPurchaseTests to use ExecutionBrowser annotation
3 |
--------------------------------------------------------------------------------
/2-speeding-up-tests/src/test/java/waitforajax/WaitForAjaxProductPurchaseTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package waitforajax;
15 |
16 | import org.openqa.selenium.By;
17 | import org.testng.Assert;
18 | import org.testng.annotations.AfterMethod;
19 | import org.testng.annotations.BeforeMethod;
20 | import org.testng.annotations.Test;
21 |
22 | public class WaitForAjaxProductPurchaseTests {
23 | private Driver driver;
24 | private static String purchaseEmail;
25 | private static String purchaseOrderNumber;
26 |
27 | @BeforeMethod
28 | public void testInit() {
29 | driver = new LoggingDriver(new WebCoreDriver());
30 | driver.start(Browser.CHROME);
31 | }
32 |
33 | @AfterMethod
34 | public void testCleanup() throws InterruptedException {
35 | driver.quit();
36 | }
37 |
38 | private String GetUserPasswordFromDb(String userName) {
39 | return "@purISQzt%%DYBnLCIhaoG6$";
40 | }
41 | }
--------------------------------------------------------------------------------
/3-tests-readability/src/main/java/core/Browser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package core;
15 |
16 | public enum Browser {
17 | CHROME,
18 | FIREFOX,
19 | EDGE,
20 | OPERA,
21 | SAFARI,
22 | INTERNET_EXPLORER
23 | }
24 |
--------------------------------------------------------------------------------
/3-tests-readability/src/main/java/core/Driver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package core;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | import java.util.List;
19 |
20 | public abstract class Driver {
21 | public abstract void start(Browser browser);
22 |
23 | public abstract void quit();
24 |
25 | public abstract void goToUrl(String url);
26 |
27 | public abstract Element findElement(By locator);
28 |
29 | public abstract List findElements(By locator);
30 |
31 | public abstract void waitForAjax();
32 |
33 | public abstract void waitUntilPageLoadsCompletely();
34 | }
35 |
--------------------------------------------------------------------------------
/3-tests-readability/src/main/java/core/DriverDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package core;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | import java.util.List;
19 |
20 | public class DriverDecorator extends Driver {
21 | protected final Driver driver;
22 |
23 | public DriverDecorator(Driver driver) {
24 | this.driver = driver;
25 | }
26 |
27 | @Override
28 | public void start(Browser browser) {
29 | driver.start(browser);
30 | }
31 |
32 | @Override
33 | public void quit() {
34 | driver.quit();
35 | }
36 |
37 | @Override
38 | public void goToUrl(String url) {
39 | driver.goToUrl(url);
40 | }
41 |
42 | @Override
43 | public Element findElement(By locator) {
44 | return driver.findElement(locator);
45 | }
46 |
47 | @Override
48 | public List findElements(By locator) {
49 | return driver.findElements(locator);
50 | }
51 |
52 | @Override
53 | public void waitForAjax() {
54 | driver.waitForAjax();
55 | }
56 |
57 | @Override
58 | public void waitUntilPageLoadsCompletely() {
59 | driver.waitUntilPageLoadsCompletely();
60 | }
61 | }
--------------------------------------------------------------------------------
/3-tests-readability/src/main/java/core/Element.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package core;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | public abstract class Element {
19 | public abstract By getBy();
20 |
21 | public abstract String getText();
22 |
23 | public abstract Boolean isEnabled();
24 |
25 | public abstract Boolean isDisplayed();
26 |
27 | public abstract void typeText(String text) throws InterruptedException;
28 |
29 | public abstract void click();
30 |
31 | public abstract String getAttribute(String attributeName);
32 |
33 | public abstract Element findElement(By locator);
34 | }
35 |
--------------------------------------------------------------------------------
/3-tests-readability/src/main/java/core/LoggingDriver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package core;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | import java.util.List;
19 |
20 | public class LoggingDriver extends DriverDecorator {
21 | public LoggingDriver(Driver driver) {
22 | super(driver);
23 | }
24 |
25 | @Override
26 | public void start(Browser browser) {
27 | System.out.printf("start browser = %s", browser.name());
28 | driver.start(browser);
29 | }
30 |
31 | @Override
32 | public void quit() {
33 | System.out.println("close browser");
34 | driver.quit();
35 | }
36 |
37 | @Override
38 | public void goToUrl(String url) {
39 | System.out.printf("go to url = %s", url);
40 | driver.goToUrl(url);
41 | }
42 |
43 | @Override
44 | public Element findElement(By locator) {
45 | System.out.println("find element");
46 | return driver.findElement(locator);
47 | }
48 |
49 | @Override
50 | public List findElements(By locator) {
51 | System.out.println("find elements");
52 | return driver.findElements(locator);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/3-tests-readability/src/main/java/pages/v4/singlefilepageobjectbasepagesections/BaseEShopPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package pages.v4.singlefilepageobjectbasepagesections;
15 |
16 | import core.Driver;
17 | import pages.v4.singlefilepageobjectbasepagesections.sections.CartInfoSection;
18 | import pages.v4.singlefilepageobjectbasepagesections.sections.MainMenuSection;
19 | import pages.v4.singlefilepageobjectbasepagesections.sections.SearchSection;
20 |
21 | public abstract class BaseEShopPage {
22 | protected final Driver driver;
23 |
24 | public BaseEShopPage(Driver driver) {
25 | this.driver = driver;
26 | }
27 |
28 | public MainMenuSection mainMenuSection() {
29 | return new MainMenuSection(driver);
30 | }
31 |
32 | public CartInfoSection cartInfoSection() {
33 | return new CartInfoSection(driver);
34 | }
35 |
36 | public SearchSection searchSection() {
37 | return new SearchSection(driver);
38 | }
39 |
40 | protected abstract String getUrl();
41 |
42 | public void open() {
43 | driver.goToUrl(getUrl());
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/3-tests-readability/src/main/java/pages/v4/singlefilepageobjectbasepagesections/MainPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package pages.v4.singlefilepageobjectbasepagesections;
15 |
16 | import core.Driver;
17 | import core.Element;
18 | import org.openqa.selenium.By;
19 |
20 | public class MainPage extends BaseEShopPage {
21 |
22 | public MainPage(Driver driver) {
23 | super(driver);
24 | }
25 |
26 | private Element addToCartFalcon9() {
27 | return driver.findElement(By.cssSelector("[data-product_id*='28']"));
28 | }
29 |
30 | private Element viewCartButton() {
31 | return driver.findElement(By.cssSelector("[class*='added_to_cart wc-forward']"));
32 | }
33 |
34 | @Override
35 | protected String getUrl() {
36 | return "http://demos.bellatrix.solutions/";
37 | }
38 |
39 | public void addRocketToShoppingCart() {
40 | open();
41 | addToCartFalcon9().click();
42 | viewCartButton().click();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/3-tests-readability/src/main/java/pages/v4/singlefilepageobjectbasepagesections/sections/BreadcrumbSection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package pages.v4.singlefilepageobjectbasepagesections.sections;
15 |
16 | import core.Driver;
17 | import core.Element;
18 | import org.openqa.selenium.By;
19 |
20 | public class BreadcrumbSection {
21 | private final Driver driver;
22 |
23 | public BreadcrumbSection(Driver driver) {
24 | this.driver = driver;
25 | }
26 |
27 | private Element breadcrumb() {
28 | return driver.findElement(By.className("woocommerce-breadcrumb"));
29 | }
30 |
31 | public void openBreadcrumbItem(String itemToOpen) {
32 | breadcrumb().findElement(By.linkText(itemToOpen)).click();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/3-tests-readability/src/main/java/pages/v4/singlefilepageobjectbasepagesections/sections/CartInfoSection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package pages.v4.singlefilepageobjectbasepagesections.sections;
15 |
16 | import core.Driver;
17 | import core.Element;
18 | import org.openqa.selenium.By;
19 |
20 | public class CartInfoSection {
21 | private final Driver driver;
22 |
23 | public CartInfoSection(Driver driver) {
24 | this.driver = driver;
25 | }
26 |
27 | private Element cartIcon() {
28 | return driver.findElement(By.className("cart-contents"));
29 | }
30 |
31 | private Element cartAmount() {
32 | return driver.findElement(By.className("amount"));
33 | }
34 |
35 | public String getCurrentAmount() {
36 | return cartAmount().getText();
37 | }
38 |
39 | public void openCart() {
40 | cartIcon().click();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/3-tests-readability/src/main/java/pages/v4/singlefilepageobjectbasepagesections/sections/SearchSection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package pages.v4.singlefilepageobjectbasepagesections.sections;
15 |
16 | import core.Driver;
17 | import core.Element;
18 | import org.openqa.selenium.By;
19 |
20 | public class SearchSection {
21 | private final Driver driver;
22 |
23 | public SearchSection(Driver driver) {
24 | this.driver = driver;
25 | }
26 |
27 | private Element searchField() {
28 | return driver.findElement(By.id("woocommerce-product-search-field-0"));
29 | }
30 |
31 | public void searchForItem(String searchText) throws InterruptedException {
32 | searchField().typeText(searchText);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/3-tests-readability/src/test/java/pages/v4/singlefilepageobjectbasepagesections/exercises.txt:
--------------------------------------------------------------------------------
1 | Exercise 1: Implement applyCoupon, increaseProductQuantity, clickProceedToCheckout, getMessageNotification and
2 | getTotal methods in pages.v4.singlefilepageobjectbasepagesections.CartPage class.
3 | Make sure that completePurchaseSuccessfully_whenNewClient test is passing.
4 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/core/Browser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package core;
15 |
16 | public enum Browser {
17 | CHROME,
18 | FIREFOX,
19 | EDGE,
20 | OPERA,
21 | SAFARI,
22 | INTERNET_EXPLORER
23 | }
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/core/Driver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package core;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | import java.util.List;
19 |
20 | public abstract class Driver {
21 | public abstract void start(Browser browser);
22 |
23 | public abstract void quit();
24 |
25 | public abstract void goToUrl(String url);
26 |
27 | public abstract Element findElement(By locator);
28 |
29 | public abstract List findElements(By locator);
30 |
31 | public abstract void waitForAjax();
32 |
33 | public abstract void waitUntilPageLoadsCompletely();
34 | }
35 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/core/DriverDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package core;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | import java.util.List;
19 |
20 | public class DriverDecorator extends Driver {
21 | protected final Driver driver;
22 |
23 | public DriverDecorator(Driver driver) {
24 | this.driver = driver;
25 | }
26 |
27 | @Override
28 | public void start(Browser browser) {
29 | driver.start(browser);
30 | }
31 |
32 | @Override
33 | public void quit() {
34 | driver.quit();
35 | }
36 |
37 | @Override
38 | public void goToUrl(String url) {
39 | driver.goToUrl(url);
40 | }
41 |
42 | @Override
43 | public Element findElement(By locator) {
44 | return driver.findElement(locator);
45 | }
46 |
47 | @Override
48 | public List findElements(By locator) {
49 | return driver.findElements(locator);
50 | }
51 |
52 | @Override
53 | public void waitForAjax() {
54 | driver.waitForAjax();
55 | }
56 |
57 | @Override
58 | public void waitUntilPageLoadsCompletely() {
59 | driver.waitUntilPageLoadsCompletely();
60 | }
61 | }
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/core/Element.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package core;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | public abstract class Element {
19 | public abstract By getBy();
20 |
21 | public abstract String getText();
22 |
23 | public abstract Boolean isEnabled();
24 |
25 | public abstract Boolean isDisplayed();
26 |
27 | public abstract void typeText(String text) throws InterruptedException;
28 |
29 | public abstract void click();
30 |
31 | public abstract String getAttribute(String attributeName);
32 |
33 | public abstract Element findElement(By locator);
34 |
35 | public abstract void waitToExists();
36 | }
37 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/core/LoggingDriver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package core;
15 |
16 | import org.openqa.selenium.By;
17 |
18 | import java.util.List;
19 |
20 | public class LoggingDriver extends DriverDecorator {
21 | public LoggingDriver(Driver driver) {
22 | super(driver);
23 | }
24 |
25 | @Override
26 | public void start(Browser browser) {
27 | System.out.printf("start browser = %s", browser.name());
28 | driver.start(browser);
29 | }
30 |
31 | @Override
32 | public void quit() {
33 | System.out.println("close browser");
34 | driver.quit();
35 | }
36 |
37 | @Override
38 | public void goToUrl(String url) {
39 | System.out.printf("go to url = %s", url);
40 | driver.goToUrl(url);
41 | }
42 |
43 | @Override
44 | public Element findElement(By locator) {
45 | System.out.println("find element");
46 | return driver.findElement(locator);
47 | }
48 |
49 | @Override
50 | public List findElements(By locator) {
51 | System.out.println("find elements");
52 | return driver.findElements(locator);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/facadedesignpattern/classic/CartPage/CartPageAssertions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package facadedesignpattern.classic.CartPage;
15 |
16 | import org.testng.Assert;
17 |
18 | public class CartPageAssertions {
19 | private final CartPageElements elements;
20 |
21 | public CartPageAssertions(CartPageElements elements) {
22 | this.elements = elements;
23 | }
24 |
25 | public void assertCouponAppliedSuccessfully() {
26 | Assert.assertEquals(elements.messageAlert().getText(), "Coupon code applied successfully.");
27 | }
28 |
29 | public void assertTotalPrice(String expectedPrice) {
30 | Assert.assertEquals(elements.totalSpan().getText(), expectedPrice);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/facadedesignpattern/classic/CheckoutPage/CheckoutAssertions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package facadedesignpattern.classic.CheckoutPage;
15 |
16 | import org.testng.Assert;
17 |
18 | public class CheckoutAssertions {
19 | private final CheckoutElements elements;
20 |
21 | public CheckoutAssertions(CheckoutElements elements) {
22 | this.elements = elements;
23 | }
24 |
25 | public void assertOrderReceived() {
26 | Assert.assertEquals(elements.receivedMessage().getText(), "Order received");
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/facadedesignpattern/classic/EShopPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package facadedesignpattern.classic;
15 |
16 | import core.Driver;
17 | import facadedesignpattern.classic.Sections.CartInfoSection;
18 | import facadedesignpattern.classic.Sections.MainMenuSection;
19 | import facadedesignpattern.classic.Sections.SearchSection;
20 |
21 | public abstract class EShopPage {
22 | protected final Driver driver;
23 |
24 | public EShopPage(Driver driver) {
25 | this.driver = driver;
26 | }
27 |
28 | public MainMenuSection mainMenuSection() {
29 | return new MainMenuSection(driver);
30 | }
31 |
32 | public CartInfoSection cartInfoSection() {
33 | return new CartInfoSection(driver);
34 | }
35 |
36 | public SearchSection searchSection() {
37 | return new SearchSection(driver);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/facadedesignpattern/classic/MainPage/MainPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package facadedesignpattern.classic.MainPage;
15 |
16 | import core.Driver;
17 | import facadedesignpattern.classic.NavigatableEShopPage;
18 |
19 | public class MainPage extends NavigatableEShopPage {
20 |
21 | public MainPage(Driver driver) {
22 | super(driver);
23 | }
24 |
25 | public MainPageElements elements() {
26 | return new MainPageElements(driver);
27 | }
28 |
29 | public MainPageAssertions assertions() {
30 | return new MainPageAssertions(elements());
31 | }
32 |
33 | @Override
34 | protected String getUrl() {
35 | return "http://demos.bellatrix.solutions/";
36 | }
37 |
38 | public void addRocketToShoppingCart(String rocketName) {
39 | open();
40 | elements().getProductBoxByName(rocketName).click();
41 | // driver.waitForAjax();
42 | elements().viewCartButton().click();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/facadedesignpattern/classic/MainPage/MainPageAssertions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package facadedesignpattern.classic.MainPage;
15 |
16 | import org.testng.Assert;
17 |
18 | public class MainPageAssertions {
19 | private final MainPageElements elements;
20 |
21 | public MainPageAssertions(MainPageElements mainPageElements) {
22 | elements = mainPageElements;
23 | }
24 |
25 | public void assertProductBoxLink(String name, String expectedLink) {
26 | var actualLink = elements.getProductBoxByName(name).getAttribute("href");
27 | Assert.assertEquals(actualLink, expectedLink);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/facadedesignpattern/classic/MainPage/MainPageElements.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package facadedesignpattern.classic.MainPage;
15 |
16 | import core.Driver;
17 | import core.Element;
18 | import org.openqa.selenium.By;
19 |
20 | public class MainPageElements {
21 | private final Driver driver;
22 |
23 | public MainPageElements(Driver driver) {
24 | this.driver = driver;
25 | }
26 |
27 | public Element addToCartFalcon9() {
28 | return driver.findElement(By.cssSelector("[data-product_id*='28']"));
29 | }
30 |
31 | public Element viewCartButton() {
32 | return driver.findElement(By.cssSelector("[class*='added_to_cart wc-forward']"));
33 | }
34 |
35 | public Element getAddToCartByName(String name) {
36 | return driver.findElement(By.xpath(String.format("//h2[text()='%s']/parent::a[1]", name)));
37 | }
38 |
39 | public Element getProductBoxByName(String name) {
40 | return driver.findElement(By.xpath(String.format("//h2[text()='%s']/parent::a[1]/following-sibling::a[1]", name)));
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/facadedesignpattern/classic/NavigatableEShopPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package facadedesignpattern.classic;
15 |
16 | import core.Driver;
17 |
18 | public abstract class NavigatableEShopPage extends EShopPage {
19 | public NavigatableEShopPage(Driver driver) {
20 | super(driver);
21 | }
22 |
23 | protected abstract String getUrl();
24 |
25 | public void open() {
26 | driver.goToUrl(getUrl());
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/facadedesignpattern/classic/Sections/BreadcrumbSection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package facadedesignpattern.classic.Sections;
15 |
16 | import core.Driver;
17 | import core.Element;
18 | import org.openqa.selenium.By;
19 |
20 | public class BreadcrumbSection {
21 | private final Driver driver;
22 |
23 | public BreadcrumbSection(Driver driver) {
24 | this.driver = driver;
25 | }
26 |
27 | private Element breadcrumb() {
28 | return driver.findElement(By.className("woocommerce-breadcrumb"));
29 | }
30 |
31 | public void openBreadcrumbItem(String itemToOpen) {
32 | breadcrumb().findElement(By.linkText(itemToOpen)).click();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/facadedesignpattern/classic/Sections/CartInfoSection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package facadedesignpattern.classic.Sections;
15 |
16 | import core.Driver;
17 | import core.Element;
18 | import org.openqa.selenium.By;
19 |
20 | public class CartInfoSection {
21 | private final Driver driver;
22 |
23 | public CartInfoSection(Driver driver) {
24 | this.driver = driver;
25 | }
26 |
27 | private Element cartIcon() {
28 | return driver.findElement(By.className("cart-contents"));
29 | }
30 |
31 | private Element cartAmount() {
32 | return driver.findElement(By.className("amount"));
33 | }
34 |
35 | public String getCurrentAmount() {
36 | return cartAmount().getText();
37 | }
38 |
39 | public void openCart() {
40 | cartIcon().click();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/facadedesignpattern/classic/Sections/SearchSection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package facadedesignpattern.classic.Sections;
15 |
16 | import core.Driver;
17 | import core.Element;
18 | import org.openqa.selenium.By;
19 |
20 | public class SearchSection {
21 | private final Driver driver;
22 |
23 | public SearchSection(Driver driver) {
24 | this.driver = driver;
25 | }
26 |
27 | private Element searchField() {
28 | return driver.findElement(By.id("woocommerce-product-search-field-0"));
29 | }
30 |
31 | public void searchForItem(String searchText) throws InterruptedException {
32 | searchField().typeText(searchText);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/pages/v5/singlefilepageobjectnavibasepagesections/EShopPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package pages.v5.singlefilepageobjectnavibasepagesections;
15 |
16 | import core.Driver;
17 | import facadedesignpattern.classic.Sections.CartInfoSection;
18 | import facadedesignpattern.classic.Sections.MainMenuSection;
19 | import facadedesignpattern.classic.Sections.SearchSection;
20 |
21 | public abstract class EShopPage {
22 | protected final Driver driver;
23 |
24 | public EShopPage(Driver driver) {
25 | this.driver = driver;
26 | }
27 |
28 | public MainMenuSection mainMenuSection() {
29 | return new MainMenuSection(driver);
30 | }
31 |
32 | public CartInfoSection cartInfoSection() {
33 | return new CartInfoSection(driver);
34 | }
35 |
36 | public SearchSection searchSection() {
37 | return new SearchSection(driver);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/pages/v5/singlefilepageobjectnavibasepagesections/MainPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package pages.v5.singlefilepageobjectnavibasepagesections;
15 |
16 | import core.Driver;
17 | import core.Element;
18 | import org.openqa.selenium.By;
19 |
20 | public class MainPage extends NavigatableEShopPage {
21 |
22 | public MainPage(Driver driver) {
23 | super(driver);
24 | }
25 |
26 | private Element addToCartFalcon9() {
27 | return driver.findElement(By.cssSelector("[data-product_id*='28']"));
28 | }
29 |
30 | private Element viewCartButton() {
31 | return driver.findElement(By.cssSelector("[class*='added_to_cart wc-forward']"));
32 | }
33 |
34 | @Override
35 | protected String getUrl() {
36 | return "http://demos.bellatrix.solutions/";
37 | }
38 |
39 | @Override
40 | protected void waitForPageLoad() {
41 | addToCartFalcon9().waitToExists();
42 | }
43 |
44 | public void addRocketToShoppingCart() {
45 | open();
46 | addToCartFalcon9().click();
47 | viewCartButton().click();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/pages/v5/singlefilepageobjectnavibasepagesections/NavigatableEShopPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package pages.v5.singlefilepageobjectnavibasepagesections;
15 |
16 | import core.Driver;
17 |
18 | public abstract class NavigatableEShopPage extends EShopPage {
19 | public NavigatableEShopPage(Driver driver) {
20 | super(driver);
21 | }
22 |
23 | protected abstract String getUrl();
24 |
25 | public void open() {
26 | driver.goToUrl(getUrl());
27 | waitForPageLoad();
28 | }
29 |
30 | protected abstract void waitForPageLoad();
31 | }
32 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/pages/v5/singlefilepageobjectnavibasepagesections/Sections/BreadcrumbSection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package pages.v5.singlefilepageobjectnavibasepagesections.Sections;
15 |
16 | import core.Driver;
17 | import core.Element;
18 | import org.openqa.selenium.By;
19 |
20 | public class BreadcrumbSection {
21 | private final Driver driver;
22 |
23 | public BreadcrumbSection(Driver driver) {
24 | this.driver = driver;
25 | }
26 |
27 | private Element breadcrumb() {
28 | return driver.findElement(By.className("woocommerce-breadcrumb"));
29 | }
30 |
31 | public void openBreadcrumbItem(String itemToOpen) {
32 | breadcrumb().findElement(By.linkText(itemToOpen)).click();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/pages/v5/singlefilepageobjectnavibasepagesections/Sections/CartInfoSection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package pages.v5.singlefilepageobjectnavibasepagesections.Sections;
15 |
16 | import core.Driver;
17 | import core.Element;
18 | import org.openqa.selenium.By;
19 |
20 | public class CartInfoSection {
21 | private final Driver driver;
22 |
23 | public CartInfoSection(Driver driver) {
24 | this.driver = driver;
25 | }
26 |
27 | private Element cartIcon() {
28 | return driver.findElement(By.className("cart-contents"));
29 | }
30 |
31 | private Element cartAmount() {
32 | return driver.findElement(By.className("amount"));
33 | }
34 |
35 | public String getCurrentAmount() {
36 | return cartAmount().getText();
37 | }
38 |
39 | public void openCart() {
40 | cartIcon().click();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/main/java/pages/v5/singlefilepageobjectnavibasepagesections/Sections/SearchSection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package pages.v5.singlefilepageobjectnavibasepagesections.Sections;
15 |
16 | import core.Driver;
17 | import core.Element;
18 | import org.openqa.selenium.By;
19 |
20 | public class SearchSection {
21 | private final Driver driver;
22 |
23 | public SearchSection(Driver driver) {
24 | this.driver = driver;
25 | }
26 |
27 | private Element searchField() {
28 | return driver.findElement(By.id("woocommerce-product-search-field-0"));
29 | }
30 |
31 | public void searchForItem(String searchText) throws InterruptedException {
32 | searchField().typeText(searchText);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/4-tests-maintainability/src/test/java/exercises.txt:
--------------------------------------------------------------------------------
1 | Exercise 1: Refactor MainPage and CartPage to be split into multiple files- one file for actions,
2 | one for elements and one more for assertions if needed. Expose assertions as a public getter.
3 | Exercise 2: Refactor tests in FacadeProductPurchaseTests to use the PurchaseFacade class.
--------------------------------------------------------------------------------
/5-api-usability/Chapter 6- API Usability.iml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/5-api-usability/src/main/java/core/Browser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package core;
15 |
16 | public enum Browser {
17 | CHROME,
18 | FIREFOX,
19 | EDGE,
20 | OPERA,
21 | SAFARI,
22 | INTERNET_EXPLORER
23 | }
24 |
--------------------------------------------------------------------------------
/5-api-usability/src/main/java/core/BrowserService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package core;
15 |
16 | public interface BrowserService {
17 | void start(Browser browser);
18 |
19 | void quit();
20 |
21 | void waitForAjax();
22 |
23 | void waitUntilPageLoadsCompletely();
24 | }
25 |
--------------------------------------------------------------------------------
/5-api-usability/src/main/java/core/CookiesService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package core;
15 |
16 | public interface CookiesService {
17 | // void addCookie(String cookieName, String cookieValue, String path);
18 | //
19 | // void deleteAllCookies();
20 | //
21 | // void deleteCookie(String cookieName);
22 | //
23 | // List getAllCookies();
24 | //
25 | // String getCookie(String cookieName);
26 | }
27 |
--------------------------------------------------------------------------------
/5-api-usability/src/main/java/core/DialogButton.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package core;
15 |
16 | public enum DialogButton {
17 | OK,
18 | CANCEL,
19 | OPEN,
20 | YES,
21 | NO,
22 | CLOSE,
23 | RUN,
24 | SAVE,
25 | }
26 |
--------------------------------------------------------------------------------
/5-api-usability/src/main/java/core/DialogService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Automate The Planet Ltd.
3 | * Author: Anton Angelov
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 http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package core;
15 |
16 | public interface DialogService {
17 | // void handle(Function