├── .editorconfig ├── .gitattributes ├── .gitignore ├── .gradle ├── 6.7 │ ├── fileChanges │ │ └── last-build.bin │ ├── fileHashes │ │ └── fileHashes.lock │ └── gc.properties ├── buildOutputCleanup │ ├── buildOutputCleanup.lock │ └── cache.properties ├── checksums │ └── checksums.lock ├── configuration-cache │ └── gc.properties └── vcs-1 │ └── gc.properties ├── .idea ├── .name ├── checkstyle-idea.xml ├── compiler.xml ├── jarRepositories.xml ├── libraries │ ├── Maven__aopalliance_aopalliance_1_0.xml │ ├── Maven__com_beust_jcommander_1_78.xml │ ├── Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_9.xml │ ├── Maven__com_fasterxml_jackson_core_jackson_core_2_8_9.xml │ ├── Maven__com_fasterxml_jackson_core_jackson_databind_2_8_9.xml │ ├── Maven__com_google_code_findbugs_jsr305_1_3_9.xml │ ├── Maven__com_google_code_gson_gson_2_8_6.xml │ ├── Maven__com_google_errorprone_error_prone_annotations_2_1_3.xml │ ├── Maven__com_google_guava_guava_25_0_jre.xml │ ├── Maven__com_google_inject_guice_no_aop_4_2_2.xml │ ├── Maven__com_google_j2objc_j2objc_annotations_1_1.xml │ ├── Maven__com_jcraft_jzlib_1_1_3.xml │ ├── Maven__com_squareup_okhttp3_okhttp_3_11_0.xml │ ├── Maven__com_squareup_okio_okio_1_14_0.xml │ ├── Maven__commons_codec_commons_codec_1_13.xml │ ├── Maven__commons_io_commons_io_2_8_0.xml │ ├── Maven__dnsjava_dnsjava_2_1_8.xml │ ├── Maven__io_github_bonigarcia_webdrivermanager_4_2_2.xml │ ├── Maven__io_netty_netty_all_4_0_51_Final.xml │ ├── Maven__javax_inject_javax_inject_1.xml │ ├── Maven__junit_junit_4_12.xml │ ├── Maven__net_bytebuddy_byte_buddy_1_8_15.xml │ ├── Maven__net_lightbody_bmp_browsermob_core_2_1_5.xml │ ├── Maven__net_lightbody_bmp_littleproxy_1_1_0_beta_bmp_17.xml │ ├── Maven__net_lightbody_bmp_mitm_2_1_5.xml │ ├── Maven__org_apache_ant_ant_1_10_3.xml │ ├── Maven__org_apache_ant_ant_launcher_1_10_3.xml │ ├── Maven__org_apache_commons_commons_compress_1_20.xml │ ├── Maven__org_apache_commons_commons_exec_1_3.xml │ ├── Maven__org_apache_commons_commons_lang3_3_11.xml │ ├── Maven__org_apache_httpcomponents_client5_httpclient5_5_0_1.xml │ ├── Maven__org_apache_httpcomponents_core5_httpcore5_5_0_1.xml │ ├── Maven__org_apache_httpcomponents_core5_httpcore5_h2_5_0_1.xml │ ├── Maven__org_bouncycastle_bcpkix_jdk15on_1_58.xml │ ├── Maven__org_bouncycastle_bcprov_jdk15on_1_58.xml │ ├── Maven__org_checkerframework_checker_compat_qual_2_0_0.xml │ ├── Maven__org_codehaus_mojo_animal_sniffer_annotations_1_14.xml │ ├── Maven__org_hamcrest_hamcrest_core_1_3.xml │ ├── Maven__org_jsoup_jsoup_1_13_1.xml │ ├── Maven__org_rauschig_jarchivelib_1_1_0.xml │ ├── Maven__org_seleniumhq_selenium_selenium_api_3_141_59.xml │ ├── Maven__org_seleniumhq_selenium_selenium_chrome_driver_3_141_59.xml │ ├── Maven__org_seleniumhq_selenium_selenium_edge_driver_3_141_59.xml │ ├── Maven__org_seleniumhq_selenium_selenium_firefox_driver_3_141_59.xml │ ├── Maven__org_seleniumhq_selenium_selenium_ie_driver_3_141_59.xml │ ├── Maven__org_seleniumhq_selenium_selenium_opera_driver_3_141_59.xml │ ├── Maven__org_seleniumhq_selenium_selenium_remote_driver_3_141_59.xml │ ├── Maven__org_seleniumhq_selenium_selenium_safari_driver_3_141_59.xml │ ├── Maven__org_seleniumhq_selenium_selenium_support_3_141_59.xml │ ├── Maven__org_slf4j_jcl_over_slf4j_1_7_25.xml │ ├── Maven__org_slf4j_slf4j_api_1_7_25.xml │ ├── Maven__org_slf4j_slf4j_api_1_7_30.xml │ ├── Maven__org_testng_testng_7_3_0.xml │ └── Maven__org_yaml_snakeyaml_1_21.xml ├── misc.xml ├── modules.xml ├── uiDesigner.xml ├── vcs.xml └── workspace.xml ├── 1-optimize-refactor-flaky-tests ├── 1-optimize-refactor-flaky-tests.iml ├── pom.xml ├── src │ ├── main │ │ ├── java │ │ │ └── decorators │ │ │ │ ├── Browser.java │ │ │ │ ├── Driver.java │ │ │ │ ├── DriverDecorator.java │ │ │ │ ├── Element.java │ │ │ │ ├── ElementDecorator.java │ │ │ │ ├── LogElement.java │ │ │ │ ├── LoggingDriver.java │ │ │ │ ├── WebCoreDriver.java │ │ │ │ └── WebCoreElement.java │ │ └── resources │ │ │ └── chromedriver.exe │ └── test │ │ ├── exercises.txt │ │ └── java │ │ ├── decorators │ │ └── DecoratorsProductPurchaseTests.java │ │ ├── hardcodedpauses │ │ └── ProductPurchaseTests.java │ │ └── webdriverwait │ │ └── WebDriverWaitProductPurchaseTests.java └── target │ └── classes │ └── chromedriver.exe ├── 2-speeding-up-tests ├── 2-speeding-up-tests.iml ├── Chapter 3- Optimize the Tests.iml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── instrumentedcode │ │ ├── Browser.java │ │ ├── Driver.java │ │ ├── DriverDecorator.java │ │ ├── Element.java │ │ ├── ElementDecorator.java │ │ ├── LogElement.java │ │ ├── LoggingDriver.java │ │ ├── WebCoreDriver.java │ │ └── WebCoreElement.java │ │ ├── reusebrowser │ │ ├── Browser.java │ │ ├── Driver.java │ │ ├── DriverDecorator.java │ │ ├── Element.java │ │ ├── ElementDecorator.java │ │ ├── LogElement.java │ │ ├── LoggingDriver.java │ │ ├── WebCoreDriver.java │ │ ├── WebCoreElement.java │ │ └── browserinfrastructure │ │ │ ├── BaseTest.java │ │ │ ├── BaseTestBehaviorObserver.java │ │ │ ├── BrowserBehavior.java │ │ │ ├── BrowserConfiguration.java │ │ │ ├── BrowserLaunchTestBehaviorObserver.java │ │ │ ├── ExecutionBrowser.java │ │ │ ├── ExecutionSubject.java │ │ │ ├── TestBehaviorObserver.java │ │ │ └── TestExecutionSubject.java │ │ ├── reusebrowsercleansession │ │ ├── Browser.java │ │ ├── Driver.java │ │ ├── DriverDecorator.java │ │ ├── Element.java │ │ ├── ElementDecorator.java │ │ ├── LogElement.java │ │ ├── LoggingDriver.java │ │ ├── WebCoreDriver.java │ │ ├── WebCoreElement.java │ │ └── browserinfrastructure │ │ │ ├── BaseTest.java │ │ │ ├── BaseTestBehaviorObserver.java │ │ │ ├── BrowserBehavior.java │ │ │ ├── BrowserConfiguration.java │ │ │ ├── BrowserLaunchTestBehaviorObserver.java │ │ │ ├── ExecutionBrowser.java │ │ │ ├── ExecutionSubject.java │ │ │ ├── TestBehaviorObserver.java │ │ │ └── TestExecutionSubject.java │ │ └── waitforajax │ │ ├── Browser.java │ │ ├── Driver.java │ │ ├── DriverDecorator.java │ │ ├── Element.java │ │ ├── ElementDecorator.java │ │ ├── LogElement.java │ │ ├── LoggingDriver.java │ │ ├── WebCoreDriver.java │ │ └── WebCoreElement.java │ └── test │ └── java │ ├── exercises.txt │ └── waitforajax │ └── WaitForAjaxProductPurchaseTests.java ├── 3-tests-readability ├── 3-tests-readability.iml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── core │ │ ├── Browser.java │ │ ├── Driver.java │ │ ├── DriverDecorator.java │ │ ├── Element.java │ │ ├── ElementDecorator.java │ │ ├── LogElement.java │ │ ├── LoggingDriver.java │ │ ├── WebCoreDriver.java │ │ └── WebCoreElement.java │ │ └── pages │ │ └── v4 │ │ └── singlefilepageobjectbasepagesections │ │ ├── BaseEShopPage.java │ │ ├── CartPage.java │ │ ├── MainPage.java │ │ └── sections │ │ ├── BreadcrumbSection.java │ │ ├── CartInfoSection.java │ │ ├── MainMenuSection.java │ │ └── SearchSection.java │ └── test │ └── java │ └── pages │ └── v4 │ └── singlefilepageobjectbasepagesections │ ├── ProductPurchaseTestsWithPageObjects.java │ └── exercises.txt ├── 4-tests-maintainability ├── 4-tests-maintainability.iml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── core │ │ ├── Browser.java │ │ ├── Driver.java │ │ ├── DriverDecorator.java │ │ ├── Element.java │ │ ├── ElementDecorator.java │ │ ├── LogElement.java │ │ ├── LoggingDriver.java │ │ ├── WebCoreDriver.java │ │ └── WebCoreElement.java │ │ ├── facadedesignpattern │ │ └── classic │ │ │ ├── CartPage │ │ │ ├── CartPage.java │ │ │ ├── CartPageAssertions.java │ │ │ └── CartPageElements.java │ │ │ ├── CheckoutPage │ │ │ ├── CheckoutAssertions.java │ │ │ ├── CheckoutElements.java │ │ │ └── CheckoutPage.java │ │ │ ├── EShopPage.java │ │ │ ├── MainPage │ │ │ ├── MainPage.java │ │ │ ├── MainPageAssertions.java │ │ │ └── MainPageElements.java │ │ │ ├── NavigatableEShopPage.java │ │ │ ├── PurchaseFacade.java │ │ │ ├── PurchaseInfo.java │ │ │ └── Sections │ │ │ ├── BreadcrumbSection.java │ │ │ ├── CartInfoSection.java │ │ │ ├── MainMenuSection.java │ │ │ └── SearchSection.java │ │ └── pages │ │ └── v5 │ │ └── singlefilepageobjectnavibasepagesections │ │ ├── CartPage.java │ │ ├── EShopPage.java │ │ ├── MainPage.java │ │ ├── NavigatableEShopPage.java │ │ └── Sections │ │ ├── BreadcrumbSection.java │ │ ├── CartInfoSection.java │ │ ├── MainMenuSection.java │ │ └── SearchSection.java │ └── test │ └── java │ ├── exercises.txt │ ├── facadedesignpattern │ └── classic │ │ └── FacadeProductPurchaseTests.java │ └── pages │ └── v5 │ └── singlefilepageobjectnavibasepagesections │ └── ProductPurchaseTestsWithPageObjects.java ├── 5-api-usability ├── 5-api-usability.iml ├── Chapter 6- API Usability.iml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── core │ │ ├── Browser.java │ │ ├── BrowserService.java │ │ ├── CookiesService.java │ │ ├── DialogButton.java │ │ ├── DialogService.java │ │ ├── Driver.java │ │ ├── DriverDecorator.java │ │ ├── Element.java │ │ ├── ElementDecorator.java │ │ ├── ElementFindService.java │ │ ├── LogElement.java │ │ ├── LoggingDriver.java │ │ ├── NavigationService.java │ │ ├── WebCoreDriver.java │ │ └── WebCoreElement.java │ │ └── pages │ │ ├── v8 │ │ └── multifilepageobjectsectionssingleton │ │ │ ├── CartPage │ │ │ ├── CartPage.java │ │ │ └── CartPageElements.java │ │ │ ├── EShopPage.java │ │ │ ├── LoggingSingletonDriver.java │ │ │ ├── MainPage │ │ │ ├── MainPage.java │ │ │ ├── MainPageAssertions.java │ │ │ └── MainPageElements.java │ │ │ ├── NavigatableEShopPage.java │ │ │ ├── Sections │ │ │ ├── BreadcrumbSection.java │ │ │ ├── CartInfoSection.java │ │ │ ├── MainMenuSection.java │ │ │ └── SearchSection.java │ │ │ └── SingletonFactory.java │ │ └── v9 │ │ └── multifilepageobjectpagesectionsapp │ │ ├── App.java │ │ ├── CartPage │ │ ├── CartPage.java │ │ └── CartPageElements.java │ │ ├── EShopPage.java │ │ ├── LoggingSingletonDriver.java │ │ ├── MainPage │ │ ├── MainPage.java │ │ ├── MainPageAssertions.java │ │ └── MainPageElements.java │ │ ├── NavigatableEShopPage.java │ │ ├── Sections │ │ ├── BreadcrumbSection.java │ │ ├── CartInfoSection.java │ │ ├── MainMenuSection.java │ │ └── SearchSection.java │ │ └── SingletonFactory.java │ └── test │ ├── exercises.txt │ └── java │ └── pages │ ├── v8 │ └── multifilepageobjectsectionssingleton │ │ └── ProductPurchaseTestsWithPageObjects.java │ └── v9 │ └── multifilepageobjectpagesectionsapp │ └── ProductPurchaseTestsWithPageObjects.java ├── 6-test-data-preparation ├── 6-test-data-preparation.iml ├── Chapter 10- Test Data Preparation.iml ├── pom.xml ├── src │ ├── main │ │ ├── java │ │ │ ├── configuration │ │ │ │ ├── BillingInfoDefaultValues.java │ │ │ │ ├── BrowserSettings.java │ │ │ │ ├── ConfigurationService.java │ │ │ │ ├── UrlDeterminer.java │ │ │ │ ├── UrlSettings.java │ │ │ │ ├── User.java │ │ │ │ └── WebSettings.java │ │ │ ├── core │ │ │ │ ├── Browser.java │ │ │ │ ├── BrowserService.java │ │ │ │ ├── CookiesService.java │ │ │ │ ├── DialogButton.java │ │ │ │ ├── DialogService.java │ │ │ │ ├── Driver.java │ │ │ │ ├── DriverDecorator.java │ │ │ │ ├── Element.java │ │ │ │ ├── ElementDecorator.java │ │ │ │ ├── ElementFindService.java │ │ │ │ ├── LogElement.java │ │ │ │ ├── LoggingDriver.java │ │ │ │ ├── NavigationService.java │ │ │ │ ├── WebCoreDriver.java │ │ │ │ └── WebCoreElement.java │ │ │ └── facadedesignpattern │ │ │ │ └── classic │ │ │ │ ├── CartPage │ │ │ │ ├── CartPage.java │ │ │ │ ├── CartPageAssertions.java │ │ │ │ └── CartPageElements.java │ │ │ │ ├── CheckoutPage │ │ │ │ ├── CheckoutAssertions.java │ │ │ │ ├── CheckoutElements.java │ │ │ │ └── CheckoutPage.java │ │ │ │ ├── EShopPage.java │ │ │ │ ├── MainPage │ │ │ │ ├── MainPage.java │ │ │ │ ├── MainPageAssertions.java │ │ │ │ └── MainPageElements.java │ │ │ │ ├── NavigatableEShopPage.java │ │ │ │ ├── PurchaseFacade.java │ │ │ │ ├── PurchaseInfo.java │ │ │ │ └── Sections │ │ │ │ ├── BreadcrumbSection.java │ │ │ │ ├── CartInfoSection.java │ │ │ │ ├── MainMenuSection.java │ │ │ │ └── SearchSection.java │ │ └── resources │ │ │ ├── application.properties │ │ │ ├── testFrameworkSettings.dev.json │ │ │ └── testFrameworkSettings.qa.json │ └── test │ │ ├── exercises.txt │ │ └── java │ │ └── facadedesignpattern │ │ └── classic │ │ └── ProductPurchaseTestsWithPageObjects.java └── target │ └── classes │ ├── application.properties │ ├── testFrameworkSettings.dev.json │ └── testFrameworkSettings.qa.json ├── Design-Patterns-for-High-Quality-Automated-Tests-Java-Edition.iml ├── LICENSE ├── design-patterns-workshop.iml ├── pom.xml └── program.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | -------------------------------------------------------------------------------- /.gradle/6.7/fileChanges/last-build.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gradle/6.7/fileHashes/fileHashes.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomateThePlanet/Design-Patterns-for-High-Quality-Automated-Tests-Java-Workshop/1eca774574a4ee67b170ec105bb040116f603193/.gradle/6.7/fileHashes/fileHashes.lock -------------------------------------------------------------------------------- /.gradle/6.7/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomateThePlanet/Design-Patterns-for-High-Quality-Automated-Tests-Java-Workshop/1eca774574a4ee67b170ec105bb040116f603193/.gradle/6.7/gc.properties -------------------------------------------------------------------------------- /.gradle/buildOutputCleanup/buildOutputCleanup.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomateThePlanet/Design-Patterns-for-High-Quality-Automated-Tests-Java-Workshop/1eca774574a4ee67b170ec105bb040116f603193/.gradle/buildOutputCleanup/buildOutputCleanup.lock -------------------------------------------------------------------------------- /.gradle/buildOutputCleanup/cache.properties: -------------------------------------------------------------------------------- 1 | #Mon Jan 11 16:44:23 EET 2021 2 | gradle.version=6.7 3 | -------------------------------------------------------------------------------- /.gradle/checksums/checksums.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomateThePlanet/Design-Patterns-for-High-Quality-Automated-Tests-Java-Workshop/1eca774574a4ee67b170ec105bb040116f603193/.gradle/checksums/checksums.lock -------------------------------------------------------------------------------- /.gradle/configuration-cache/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomateThePlanet/Design-Patterns-for-High-Quality-Automated-Tests-Java-Workshop/1eca774574a4ee67b170ec105bb040116f603193/.gradle/configuration-cache/gc.properties -------------------------------------------------------------------------------- /.gradle/vcs-1/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AutomateThePlanet/Design-Patterns-for-High-Quality-Automated-Tests-Java-Workshop/1eca774574a4ee67b170ec105bb040116f603193/.gradle/vcs-1/gc.properties -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | design-patterns-for-high-quality-automated-tests -------------------------------------------------------------------------------- /.idea/checkstyle-idea.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__aopalliance_aopalliance_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_beust_jcommander_1_78.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_9.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_8_9.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_8_9.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_google_code_findbugs_jsr305_1_3_9.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_google_code_gson_gson_2_8_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_google_errorprone_error_prone_annotations_2_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_google_guava_guava_25_0_jre.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_google_inject_guice_no_aop_4_2_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_google_j2objc_j2objc_annotations_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_jcraft_jzlib_1_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_squareup_okhttp3_okhttp_3_11_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_squareup_okio_okio_1_14_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_codec_commons_codec_1_13.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_io_commons_io_2_8_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__dnsjava_dnsjava_2_1_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_github_bonigarcia_webdrivermanager_4_2_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_netty_netty_all_4_0_51_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_inject_javax_inject_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__junit_junit_4_12.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__net_bytebuddy_byte_buddy_1_8_15.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__net_lightbody_bmp_browsermob_core_2_1_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__net_lightbody_bmp_littleproxy_1_1_0_beta_bmp_17.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__net_lightbody_bmp_mitm_2_1_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_ant_ant_1_10_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_ant_ant_launcher_1_10_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_commons_commons_compress_1_20.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_commons_commons_exec_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_commons_commons_lang3_3_11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_httpcomponents_client5_httpclient5_5_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_httpcomponents_core5_httpcore5_5_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_httpcomponents_core5_httpcore5_h2_5_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bouncycastle_bcpkix_jdk15on_1_58.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bouncycastle_bcprov_jdk15on_1_58.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_checkerframework_checker_compat_qual_2_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_codehaus_mojo_animal_sniffer_annotations_1_14.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_jsoup_jsoup_1_13_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_rauschig_jarchivelib_1_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_seleniumhq_selenium_selenium_api_3_141_59.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_seleniumhq_selenium_selenium_chrome_driver_3_141_59.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_seleniumhq_selenium_selenium_edge_driver_3_141_59.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_seleniumhq_selenium_selenium_firefox_driver_3_141_59.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_seleniumhq_selenium_selenium_ie_driver_3_141_59.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_seleniumhq_selenium_selenium_opera_driver_3_141_59.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_seleniumhq_selenium_selenium_remote_driver_3_141_59.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_seleniumhq_selenium_selenium_safari_driver_3_141_59.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_seleniumhq_selenium_selenium_support_3_141_59.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_jcl_over_slf4j_1_7_25.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_30.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_testng_testng_7_3_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_yaml_snakeyaml_1_21.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 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 function, DialogButton dialogButton); 18 | } 19 | -------------------------------------------------------------------------------- /5-api-usability/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 | public abstract class Driver implements NavigationService, BrowserService, CookiesService, ElementFindService, DialogService { 17 | } -------------------------------------------------------------------------------- /5-api-usability/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 | -------------------------------------------------------------------------------- /5-api-usability/src/main/java/core/ElementFindService.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 interface ElementFindService { 21 | Element findElement(By locator); 22 | 23 | List findElements(By locator); 24 | } 25 | -------------------------------------------------------------------------------- /5-api-usability/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.println(String.format("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.println(String.format("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 | -------------------------------------------------------------------------------- /5-api-usability/src/main/java/core/NavigationService.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 NavigationService { 17 | void goToUrl(String url); 18 | 19 | String getUrl(); 20 | } 21 | -------------------------------------------------------------------------------- /5-api-usability/src/main/java/pages/v8/multifilepageobjectsectionssingleton/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.v8.multifilepageobjectsectionssingleton; 15 | 16 | import core.ElementFindService; 17 | import pages.v8.multifilepageobjectsectionssingleton.Sections.CartInfoSection; 18 | import pages.v8.multifilepageobjectsectionssingleton.Sections.MainMenuSection; 19 | import pages.v8.multifilepageobjectsectionssingleton.Sections.SearchSection; 20 | 21 | public abstract class EShopPage { 22 | protected final ElementFindService elementFindService; 23 | 24 | protected EShopPage() { 25 | this.elementFindService = LoggingSingletonDriver.getInstance(); 26 | } 27 | 28 | public MainMenuSection mainMenuSection() { 29 | return new MainMenuSection(elementFindService); 30 | } 31 | 32 | public CartInfoSection cartInfoSection() { 33 | return new CartInfoSection(elementFindService); 34 | } 35 | 36 | public SearchSection searchSection() { 37 | return new SearchSection(elementFindService); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /5-api-usability/src/main/java/pages/v8/multifilepageobjectsectionssingleton/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 pages.v8.multifilepageobjectsectionssingleton.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 | -------------------------------------------------------------------------------- /5-api-usability/src/main/java/pages/v8/multifilepageobjectsectionssingleton/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 pages.v8.multifilepageobjectsectionssingleton.MainPage; 15 | 16 | import core.Element; 17 | import core.ElementFindService; 18 | import org.openqa.selenium.By; 19 | 20 | public class MainPageElements { 21 | private final ElementFindService elementFindService; 22 | 23 | public MainPageElements(ElementFindService elementFindService) { 24 | this.elementFindService = elementFindService; 25 | } 26 | 27 | public Element addToCartFalcon9() { 28 | return elementFindService.findElement(By.cssSelector("[data-product_id*='28']")); 29 | } 30 | 31 | public Element viewCartButton() { 32 | return elementFindService.findElement(By.cssSelector("[class*='added_to_cart wc-forward']")); 33 | } 34 | 35 | public Element getProductBoxByName(String name) { 36 | return elementFindService.findElement(By.xpath(String.format("//h2[text()='%s']/parent::a[1]", name))); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /5-api-usability/src/main/java/pages/v8/multifilepageobjectsectionssingleton/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.v8.multifilepageobjectsectionssingleton; 15 | 16 | import core.NavigationService; 17 | 18 | public abstract class NavigatableEShopPage extends EShopPage { 19 | protected final NavigationService navigationService; 20 | 21 | protected NavigatableEShopPage() { 22 | this.navigationService = LoggingSingletonDriver.getInstance(); 23 | } 24 | 25 | protected abstract String getUrl(); 26 | 27 | public void open() { 28 | navigationService.goToUrl(getUrl()); 29 | waitForPageLoad(); 30 | } 31 | 32 | protected abstract void waitForPageLoad(); 33 | } 34 | -------------------------------------------------------------------------------- /5-api-usability/src/main/java/pages/v8/multifilepageobjectsectionssingleton/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.v8.multifilepageobjectsectionssingleton.Sections; 15 | 16 | import core.Element; 17 | import core.ElementFindService; 18 | import org.openqa.selenium.By; 19 | 20 | public class BreadcrumbSection { 21 | private final ElementFindService elementFindService; 22 | 23 | public BreadcrumbSection(ElementFindService elementFindService) { 24 | this.elementFindService = elementFindService; 25 | } 26 | 27 | private Element breadcrumb() { 28 | return elementFindService.findElement(By.className("woocommerce-breadcrumb")); 29 | } 30 | 31 | public void openBreadcrumbItem(String itemToOpen) { 32 | breadcrumb().findElement(By.linkText(itemToOpen)).click(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /5-api-usability/src/main/java/pages/v8/multifilepageobjectsectionssingleton/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.v8.multifilepageobjectsectionssingleton.Sections; 15 | 16 | import core.Element; 17 | import core.ElementFindService; 18 | import org.openqa.selenium.By; 19 | 20 | public class CartInfoSection { 21 | private final ElementFindService elementFindService; 22 | 23 | public CartInfoSection(ElementFindService elementFindService) { 24 | this.elementFindService = elementFindService; 25 | } 26 | 27 | private Element cartIcon() { 28 | return elementFindService.findElement(By.className("cart-contents")); 29 | } 30 | 31 | private Element cartAmount() { 32 | return elementFindService.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 | -------------------------------------------------------------------------------- /5-api-usability/src/main/java/pages/v8/multifilepageobjectsectionssingleton/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.v8.multifilepageobjectsectionssingleton.Sections; 15 | 16 | import core.Element; 17 | import core.ElementFindService; 18 | import org.openqa.selenium.By; 19 | 20 | public class SearchSection { 21 | private final ElementFindService elementFindService; 22 | 23 | public SearchSection(ElementFindService elementFindService) { 24 | this.elementFindService = elementFindService; 25 | } 26 | 27 | private Element searchField() { 28 | return elementFindService.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 | -------------------------------------------------------------------------------- /5-api-usability/src/main/java/pages/v9/multifilepageobjectpagesectionsapp/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.v9.multifilepageobjectpagesectionsapp; 15 | 16 | import core.ElementFindService; 17 | import pages.v9.multifilepageobjectpagesectionsapp.Sections.CartInfoSection; 18 | import pages.v9.multifilepageobjectpagesectionsapp.Sections.MainMenuSection; 19 | import pages.v9.multifilepageobjectpagesectionsapp.Sections.SearchSection; 20 | 21 | public abstract class EShopPage { 22 | protected final ElementFindService elementFindService; 23 | 24 | public EShopPage(ElementFindService elementFindService) { 25 | this.elementFindService = elementFindService; 26 | } 27 | 28 | public MainMenuSection mainMenuSection() { 29 | return new MainMenuSection(elementFindService); 30 | } 31 | 32 | public CartInfoSection cartInfoSection() { 33 | return new CartInfoSection(elementFindService); 34 | } 35 | 36 | public SearchSection searchSection() { 37 | return new SearchSection(elementFindService); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /5-api-usability/src/main/java/pages/v9/multifilepageobjectpagesectionsapp/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 pages.v9.multifilepageobjectpagesectionsapp.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 | -------------------------------------------------------------------------------- /5-api-usability/src/main/java/pages/v9/multifilepageobjectpagesectionsapp/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 pages.v9.multifilepageobjectpagesectionsapp.MainPage; 15 | 16 | import core.Element; 17 | import core.ElementFindService; 18 | import org.openqa.selenium.By; 19 | 20 | public class MainPageElements { 21 | private final ElementFindService elementFindService; 22 | 23 | public MainPageElements(ElementFindService elementFindService) { 24 | this.elementFindService = elementFindService; 25 | } 26 | 27 | public Element addToCartFalcon9() { 28 | return elementFindService.findElement(By.cssSelector("[data-product_id*='28']")); 29 | } 30 | 31 | public Element viewCartButton() { 32 | return elementFindService.findElement(By.cssSelector("[class*='added_to_cart wc-forward']")); 33 | } 34 | 35 | public Element getProductBoxByName(String name) { 36 | return elementFindService.findElement(By.xpath(String.format("//h2[text()='%s']/parent::a[1]", name))); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /5-api-usability/src/main/java/pages/v9/multifilepageobjectpagesectionsapp/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.v9.multifilepageobjectpagesectionsapp; 15 | 16 | import core.ElementFindService; 17 | import core.NavigationService; 18 | 19 | public abstract class NavigatableEShopPage extends EShopPage { 20 | protected final NavigationService navigationService; 21 | 22 | public NavigatableEShopPage(ElementFindService elementFindService, NavigationService navigationService) { 23 | super(elementFindService); 24 | this.navigationService = navigationService; 25 | } 26 | 27 | protected abstract String getUrl(); 28 | 29 | public void open() { 30 | navigationService.goToUrl(getUrl()); 31 | waitForPageLoad(); 32 | } 33 | 34 | protected abstract void waitForPageLoad(); 35 | } 36 | -------------------------------------------------------------------------------- /5-api-usability/src/main/java/pages/v9/multifilepageobjectpagesectionsapp/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.v9.multifilepageobjectpagesectionsapp.Sections; 15 | 16 | import core.Element; 17 | import core.ElementFindService; 18 | import org.openqa.selenium.By; 19 | 20 | public class BreadcrumbSection { 21 | private final ElementFindService elementFindService; 22 | 23 | public BreadcrumbSection(ElementFindService elementFindService) { 24 | this.elementFindService = elementFindService; 25 | } 26 | 27 | private Element breadcrumb() { 28 | return elementFindService.findElement(By.className("woocommerce-breadcrumb")); 29 | } 30 | 31 | public void openBreadcrumbItem(String itemToOpen) { 32 | breadcrumb().findElement(By.linkText(itemToOpen)).click(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /5-api-usability/src/main/java/pages/v9/multifilepageobjectpagesectionsapp/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.v9.multifilepageobjectpagesectionsapp.Sections; 15 | 16 | import core.Element; 17 | import core.ElementFindService; 18 | import org.openqa.selenium.By; 19 | 20 | public class CartInfoSection { 21 | private final ElementFindService elementFindService; 22 | 23 | public CartInfoSection(ElementFindService elementFindService) { 24 | this.elementFindService = elementFindService; 25 | } 26 | 27 | private Element cartIcon() { 28 | return elementFindService.findElement(By.className("cart-contents")); 29 | } 30 | 31 | private Element cartAmount() { 32 | return elementFindService.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 | -------------------------------------------------------------------------------- /5-api-usability/src/main/java/pages/v9/multifilepageobjectpagesectionsapp/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.v9.multifilepageobjectpagesectionsapp.Sections; 15 | 16 | import core.Element; 17 | import core.ElementFindService; 18 | import org.openqa.selenium.By; 19 | 20 | public class SearchSection { 21 | private final ElementFindService elementFindService; 22 | 23 | public SearchSection(ElementFindService elementFindService) { 24 | this.elementFindService = elementFindService; 25 | } 26 | 27 | private Element searchField() { 28 | return elementFindService.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 | -------------------------------------------------------------------------------- /5-api-usability/src/test/exercises.txt: -------------------------------------------------------------------------------- 1 | Exercise 1: Refactor singleton tests to use the facade design pattern 2 | Exercise 2: Refactor app design pattern pages to be fluent. Refactor the tests to use the new fluent API syntax. -------------------------------------------------------------------------------- /6-test-data-preparation/Chapter 10- Test Data Preparation.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /6-test-data-preparation/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 18 | 19 | design-patterns-for-high-quality-automated-tests 20 | solutions.bellatrix 21 | 1.0-SNAPSHOT 22 | 23 | 4.0.0 24 | 25 | chapter10-test-data-preparation 26 | 27 | 28 | 29 | net.lightbody.bmp 30 | browsermob-core 31 | 2.1.5 32 | 33 | 34 | com.google.code.gson 35 | gson 36 | 2.8.6 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /6-test-data-preparation/src/main/java/configuration/BrowserSettings.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 configuration; 15 | 16 | public class BrowserSettings { 17 | private int pageLoadTimeout; 18 | private int scriptTimeout; 19 | 20 | public int getPageLoadTimeout() { 21 | return pageLoadTimeout; 22 | } 23 | 24 | public int getScriptTimeout() { 25 | return scriptTimeout; 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return "BrowserSettings{" + 31 | "pageLoadTimeout=" + pageLoadTimeout + 32 | ", scriptTimeout=" + scriptTimeout + 33 | '}'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /6-test-data-preparation/src/main/java/configuration/UrlDeterminer.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 configuration; 15 | 16 | import org.apache.hc.core5.net.URIBuilder; 17 | import java.io.IOException; 18 | import java.net.URI; 19 | import java.net.URISyntaxException; 20 | 21 | public class UrlDeterminer { 22 | public static String getShopUrl(String urlPart) { 23 | return contactUrls(ConfigurationService.get(UrlSettings.class).getShopUrl(), urlPart); 24 | } 25 | 26 | public static String getAccountUrl(String urlPart) { 27 | return contactUrls(ConfigurationService.get(UrlSettings.class).getAccountUrl(), urlPart); 28 | } 29 | 30 | private static String contactUrls(String url, String part) { 31 | try { 32 | var uriBuilder = new URIBuilder(url); 33 | URI uri = uriBuilder.setPath(uriBuilder.getPath() + part) 34 | .build() 35 | .normalize(); 36 | return uri.toString(); 37 | } 38 | catch (URISyntaxException ex) { 39 | return null; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /6-test-data-preparation/src/main/java/configuration/UrlSettings.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 configuration; 15 | 16 | public class UrlSettings { 17 | private String shopUrl; 18 | private String accountUrl; 19 | 20 | public String getShopUrl() { 21 | return shopUrl; 22 | } 23 | 24 | public String getAccountUrl() { 25 | return accountUrl; 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return "UrlSettings{" + 31 | "shopUrl='" + shopUrl + '\'' + 32 | ", accountUrl='" + accountUrl + '\'' + 33 | '}'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 | import java.io.IOException; 17 | 18 | public interface BrowserService { 19 | void start(Browser browser) throws IOException; 20 | void quit(); 21 | void waitForAjax(); 22 | void waitUntilPageLoadsCompletely(); 23 | } 24 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 function, DialogButton dialogButton); 18 | } 19 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 | import org.openqa.selenium.support.ui.WebDriverWait; 18 | 19 | import java.io.IOException; 20 | import java.util.List; 21 | 22 | public abstract class Driver implements NavigationService, BrowserService, CookiesService, ElementFindService, DialogService { 23 | public abstract WebDriverWait getBrowserWait(); 24 | } 25 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 | 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 | public abstract void waitToExists(); 27 | public abstract Element findElement(By locator); 28 | } 29 | -------------------------------------------------------------------------------- /6-test-data-preparation/src/main/java/core/ElementFindService.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 interface ElementFindService { 21 | Element findElement(By locator); 22 | List findElements(By locator); 23 | } 24 | -------------------------------------------------------------------------------- /6-test-data-preparation/src/main/java/core/NavigationService.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 NavigationService { 17 | void goToUrl(String url); 18 | String getUrl(); 19 | } 20 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 | { 27 | Assert.assertEquals(elements.messageAlert().getText(), "Coupon code applied successfully."); 28 | } 29 | 30 | public void assertTotalPrice(String expectedPrice) 31 | { 32 | Assert.assertEquals(elements.totalSpan().getText(), expectedPrice); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 | { 27 | Assert.assertEquals(elements.receivedMessage().getText(), "Order received"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 | { 23 | super(driver); 24 | } 25 | 26 | public MainPageElements elements() { 27 | return new MainPageElements(driver); 28 | } 29 | 30 | public MainPageAssertions assertions() { 31 | return new MainPageAssertions(elements()); 32 | } 33 | 34 | @Override 35 | protected String getUrl() { 36 | return "http://demos.bellatrix.solutions/"; 37 | } 38 | 39 | @Override 40 | protected void waitForPageLoad() { 41 | elements().addToCartFalcon9().waitToExists(); 42 | } 43 | 44 | public void addRocketToShoppingCart(String rocketName) 45 | { 46 | open(); 47 | elements().getProductBoxByName(rocketName).click(); 48 | // driver.waitForAjax(); 49 | elements().viewCartButton().click(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 | { 27 | driver.goToUrl(getUrl()); 28 | waitForPageLoad(); 29 | } 30 | 31 | protected abstract void waitForPageLoad(); 32 | } 33 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 | { 33 | breadcrumb().findElement(By.linkText(itemToOpen)).click(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 | { 37 | return cartAmount().getText(); 38 | } 39 | 40 | public void openCart() 41 | { 42 | cartIcon().click(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /6-test-data-preparation/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 | -------------------------------------------------------------------------------- /6-test-data-preparation/src/main/resources/application.properties: -------------------------------------------------------------------------------- 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 | environment=qa -------------------------------------------------------------------------------- /6-test-data-preparation/src/main/resources/testFrameworkSettings.dev.json: -------------------------------------------------------------------------------- 1 | { 2 | "webSettings": { 3 | "baseUrl": "http://demos.bellatrix.solutions/", 4 | "elementWaitTimeout": "30", 5 | "chrome": { 6 | "pageLoadTimeout": "120", 7 | "scriptTimeout": "5", 8 | "artificialDelayBeforeAction": "0" 9 | }, 10 | "firefox": { 11 | "pageLoadTimeout": "30", 12 | "scriptTimeout": "1", 13 | "artificialDelayBeforeAction": "0" 14 | }, 15 | "edge": { 16 | "pageLoadTimeout": "30", 17 | "scriptTimeout": "1", 18 | "artificialDelayBeforeAction": "0" 19 | }, 20 | "internetExplorer": { 21 | "pageLoadTimeout": "30", 22 | "scriptTimeout": "1", 23 | "artificialDelayBeforeAction": "0" 24 | }, 25 | "opera": { 26 | "pageLoadTimeout": "30", 27 | "scriptTimeout": "1", 28 | "artificialDelayBeforeAction": "0" 29 | }, 30 | "safari": { 31 | "pageLoadTimeout": "30", 32 | "scriptTimeout": "1", 33 | "artificialDelayBeforeAction": "0" 34 | } 35 | }, 36 | "urlSettings": { 37 | "shopUrl": "http://demos.bellatrix.solutions/cart/", 38 | "accountUrl": "http://demos.bellatrix.solutions/account/" 39 | }, 40 | "billingInfoDefaultValues": { 41 | "email": "info@spaceFlowers.com", 42 | "company": "Space Flowers", 43 | "country": "Germany", 44 | "firstName": "Anton", 45 | "lastName": "Angelov", 46 | "phone": "+00498888999281", 47 | "zip": "10115", 48 | "city": "Berlin", 49 | "address1": "1 Willi Brandt Avenue Tiergarten", 50 | "address2": "2 Willi Brandt Avenue Tiergarten" 51 | } 52 | } -------------------------------------------------------------------------------- /6-test-data-preparation/src/main/resources/testFrameworkSettings.qa.json: -------------------------------------------------------------------------------- 1 | { 2 | "webSettings": { 3 | "baseUrl": "http://qa.bellatrix.solutions/", 4 | "elementWaitTimeout": "60", 5 | "chrome": { 6 | "pageLoadTimeout": "120", 7 | "scriptTimeout": "5", 8 | "artificialDelayBeforeAction": "0" 9 | }, 10 | "firefox": { 11 | "pageLoadTimeout": "60", 12 | "scriptTimeout": "1", 13 | "artificialDelayBeforeAction": "0" 14 | }, 15 | "edge": { 16 | "pageLoadTimeout": "60", 17 | "scriptTimeout": "1", 18 | "artificialDelayBeforeAction": "0" 19 | }, 20 | "internetExplorer": { 21 | "pageLoadTimeout": "60", 22 | "scriptTimeout": "1", 23 | "artificialDelayBeforeAction": "0" 24 | }, 25 | "opera": { 26 | "pageLoadTimeout": "60", 27 | "scriptTimeout": "1", 28 | "artificialDelayBeforeAction": "0" 29 | }, 30 | "safari": { 31 | "pageLoadTimeout": "60", 32 | "scriptTimeout": "1", 33 | "artificialDelayBeforeAction": "0" 34 | } 35 | }, 36 | "urlSettings": { 37 | "shopUrl": "http://qa.bellatrix.solutions/cart/", 38 | "accountUrl": "http://qa.bellatrix.solutions/account/" 39 | }, 40 | "billingInfoDefaultValues": { 41 | "email": "info@spaceFlowers.com", 42 | "company": "Space Flowers", 43 | "country": "Germany", 44 | "firstName": "Anton", 45 | "lastName": "Angelov", 46 | "phone": "+00498888999281", 47 | "zip": "10115", 48 | "city": "Berlin", 49 | "address1": "1 Willi Brandt Avenue Tiergarten", 50 | "address2": "2 Willi Brandt Avenue Tiergarten" 51 | } 52 | } -------------------------------------------------------------------------------- /6-test-data-preparation/src/test/exercises.txt: -------------------------------------------------------------------------------- 1 | Exercise 1: Create new class BillingInfoDefaultValues for representing a new JSON config section with default billing info. 2 | Refactor PurchaseInfo class to use the new configuration. -------------------------------------------------------------------------------- /6-test-data-preparation/target/classes/application.properties: -------------------------------------------------------------------------------- 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 | environment=qa -------------------------------------------------------------------------------- /6-test-data-preparation/target/classes/testFrameworkSettings.dev.json: -------------------------------------------------------------------------------- 1 | { 2 | "webSettings": { 3 | "baseUrl": "http://demos.bellatrix.solutions/", 4 | "elementWaitTimeout": "30", 5 | "chrome": { 6 | "pageLoadTimeout": "120", 7 | "scriptTimeout": "5", 8 | "artificialDelayBeforeAction": "0" 9 | }, 10 | "firefox": { 11 | "pageLoadTimeout": "30", 12 | "scriptTimeout": "1", 13 | "artificialDelayBeforeAction": "0" 14 | }, 15 | "edge": { 16 | "pageLoadTimeout": "30", 17 | "scriptTimeout": "1", 18 | "artificialDelayBeforeAction": "0" 19 | }, 20 | "internetExplorer": { 21 | "pageLoadTimeout": "30", 22 | "scriptTimeout": "1", 23 | "artificialDelayBeforeAction": "0" 24 | }, 25 | "opera": { 26 | "pageLoadTimeout": "30", 27 | "scriptTimeout": "1", 28 | "artificialDelayBeforeAction": "0" 29 | }, 30 | "safari": { 31 | "pageLoadTimeout": "30", 32 | "scriptTimeout": "1", 33 | "artificialDelayBeforeAction": "0" 34 | } 35 | }, 36 | "urlSettings": { 37 | "shopUrl": "http://demos.bellatrix.solutions/cart/", 38 | "accountUrl": "http://demos.bellatrix.solutions/account/" 39 | }, 40 | "billingInfoDefaultValues": { 41 | "email": "info@spaceFlowers.com", 42 | "company": "Space Flowers", 43 | "country": "Germany", 44 | "firstName": "Anton", 45 | "lastName": "Angelov", 46 | "phone": "+00498888999281", 47 | "zip": "10115", 48 | "city": "Berlin", 49 | "address1": "1 Willi Brandt Avenue Tiergarten", 50 | "address2": "2 Willi Brandt Avenue Tiergarten" 51 | } 52 | } -------------------------------------------------------------------------------- /6-test-data-preparation/target/classes/testFrameworkSettings.qa.json: -------------------------------------------------------------------------------- 1 | { 2 | "webSettings": { 3 | "baseUrl": "http://qa.bellatrix.solutions/", 4 | "elementWaitTimeout": "60", 5 | "chrome": { 6 | "pageLoadTimeout": "120", 7 | "scriptTimeout": "5", 8 | "artificialDelayBeforeAction": "0" 9 | }, 10 | "firefox": { 11 | "pageLoadTimeout": "60", 12 | "scriptTimeout": "1", 13 | "artificialDelayBeforeAction": "0" 14 | }, 15 | "edge": { 16 | "pageLoadTimeout": "60", 17 | "scriptTimeout": "1", 18 | "artificialDelayBeforeAction": "0" 19 | }, 20 | "internetExplorer": { 21 | "pageLoadTimeout": "60", 22 | "scriptTimeout": "1", 23 | "artificialDelayBeforeAction": "0" 24 | }, 25 | "opera": { 26 | "pageLoadTimeout": "60", 27 | "scriptTimeout": "1", 28 | "artificialDelayBeforeAction": "0" 29 | }, 30 | "safari": { 31 | "pageLoadTimeout": "60", 32 | "scriptTimeout": "1", 33 | "artificialDelayBeforeAction": "0" 34 | } 35 | }, 36 | "urlSettings": { 37 | "shopUrl": "http://qa.bellatrix.solutions/cart/", 38 | "accountUrl": "http://qa.bellatrix.solutions/account/" 39 | }, 40 | "billingInfoDefaultValues": { 41 | "email": "info@spaceFlowers.com", 42 | "company": "Space Flowers", 43 | "country": "Germany", 44 | "firstName": "Anton", 45 | "lastName": "Angelov", 46 | "phone": "+00498888999281", 47 | "zip": "10115", 48 | "city": "Berlin", 49 | "address1": "1 Willi Brandt Avenue Tiergarten", 50 | "address2": "2 Willi Brandt Avenue Tiergarten" 51 | } 52 | } -------------------------------------------------------------------------------- /Design-Patterns-for-High-Quality-Automated-Tests-Java-Edition.iml: -------------------------------------------------------------------------------- 1 | 2 | --------------------------------------------------------------------------------