From d09c68d9bed467b30628845f411064a353849155 Mon Sep 17 00:00:00 2001 From: sergiomartins Date: Fri, 8 May 2020 09:32:50 +0100 Subject: [PATCH 1/2] fix firefox integration tests --- docker-compose.yaml | 7 +------ src/main/resources/archetype-resources/docker-compose.yaml | 4 ++-- .../src/test/java/tests/ExampleTest.java | 2 +- src/test/resources/projects/ui_tests/goal.txt | 5 +++-- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index d4ac302..fd46435 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -6,8 +6,7 @@ services: image: jamesdbloom/mockserver:mockserver-5.7.2 container_name: mockserver ports: - - "3000:1080" - - "3001:1090" + - "1080:1080" selenium-hub: image: selenium/hub:3.141 @@ -20,8 +19,6 @@ services: chrome: image: selenium/node-chrome:3.141 container_name: chrome - ports: - - "5900:5900" volumes: - /dev/shm:/dev/shm depends_on: @@ -33,8 +30,6 @@ services: firefox: image: selenium/node-firefox:3.141 container_name: firefox - ports: - - "5901:5900" volumes: - /dev/shm:/dev/shm depends_on: diff --git a/src/main/resources/archetype-resources/docker-compose.yaml b/src/main/resources/archetype-resources/docker-compose.yaml index 656a849..06b3ac9 100644 --- a/src/main/resources/archetype-resources/docker-compose.yaml +++ b/src/main/resources/archetype-resources/docker-compose.yaml @@ -37,8 +37,8 @@ services: image: jamesdbloom/mockserver:mockserver-5.7.2 container_name: mockserver ports: - - "3000:1080" - - "3001:1090" + - "1080:1080" + - "1090:1090" #end selenium-hub: diff --git a/src/main/resources/archetype-resources/src/test/java/tests/ExampleTest.java b/src/main/resources/archetype-resources/src/test/java/tests/ExampleTest.java index 0cdc052..5e1675d 100644 --- a/src/main/resources/archetype-resources/src/test/java/tests/ExampleTest.java +++ b/src/main/resources/archetype-resources/src/test/java/tests/ExampleTest.java @@ -41,7 +41,7 @@ public void testExampleOne() { @Test(description = "Test based on mock server expectations") public void testExampleTwo() { // This is just an example of the expectation currently being mocked by using MockServer on ${localhost} - open("http://mockserver:3000/login"); + open("http://mockserver:1080/login"); logger().info("Example info log"); logger().warn("Example warn log"); diff --git a/src/test/resources/projects/ui_tests/goal.txt b/src/test/resources/projects/ui_tests/goal.txt index 5783140..1808f4b 100644 --- a/src/test/resources/projects/ui_tests/goal.txt +++ b/src/test/resources/projects/ui_tests/goal.txt @@ -1,4 +1,5 @@ test \ -Dselenide.remote=http://0.0.0.0:4444/wd/hub \ --Dmock.server.address=0.0.0.0:3000 \ --Dlistener=io/company/utils/listeners/MockServerListener.java +-Dmock.server.address=0.0.0.0:1080 \ +-Dlistener=io/company/utils/listeners/MockServerListener.java \ +-Dselenide.browser=firefox From ce61b7de670d670572007bb940b8b8573875a85b Mon Sep 17 00:00:00 2001 From: sergiomartins Date: Fri, 8 May 2020 11:05:28 +0100 Subject: [PATCH 2/2] change mockserver initialization logic --- README.md | 2 +- pom.xml | 2 +- .../src/test/java/base/DriverContext.java | 2 +- .../test/java/base/FrameworkBootstrap.java | 26 +++---------------- .../src/test/java/base/MockContext.java | 22 +++++++--------- 5 files changed, 17 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index bd584cf..d61a239 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Features: ```shell script $ mvn archetype:generate -DarchetypeGroupId=com.github.sergiomartins8 \ -DarchetypeArtifactId=ui-automation-bootstrap \ - -DarchetypeVersion=1.0.0 \ + -DarchetypeVersion=1.1.0 \ -DgroupId=awesome.group.id \ -DartifactId=awesome-template \ -Dcheckstyle=true \ diff --git a/pom.xml b/pom.xml index 10caaee..14424ea 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.github.sergiomartins8 ui-automation-bootstrap - 1.0.0 + 1.1.0 maven-archetype ui-automation-bootstrap diff --git a/src/main/resources/archetype-resources/src/test/java/base/DriverContext.java b/src/main/resources/archetype-resources/src/test/java/base/DriverContext.java index 0dce36e..363e701 100644 --- a/src/main/resources/archetype-resources/src/test/java/base/DriverContext.java +++ b/src/main/resources/archetype-resources/src/test/java/base/DriverContext.java @@ -17,7 +17,7 @@ import static com.codeborne.selenide.WebDriverRunner.getWebDriver; /** - * Holds methods that initialize (and teardown) the required driver; locally or remotely. + * Holds methods that initialize and teardown the required driver; locally or remotely. *
* Also, an instance to the {@link Browser} in which browser actions can be performed */ diff --git a/src/main/resources/archetype-resources/src/test/java/base/FrameworkBootstrap.java b/src/main/resources/archetype-resources/src/test/java/base/FrameworkBootstrap.java index ab965bd..95d77b9 100644 --- a/src/main/resources/archetype-resources/src/test/java/base/FrameworkBootstrap.java +++ b/src/main/resources/archetype-resources/src/test/java/base/FrameworkBootstrap.java @@ -1,41 +1,23 @@ package ${package}.base; -#if (${mockserver} == 'true') import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; -import ${package}.utils.config.CustomConfiguration; -#end import ${package}.utils.logging.Loggable; /** * Where it all starts. *
* The framework is initialized here with all the required configurations. -#if (${mockserver} == 'true') - * It also takes care of the {@link MockContext} initialization and teardown. -#end */ public abstract class FrameworkBootstrap implements Loggable { -#if (${mockserver} == 'true') - /** - * Tells {@link MockContext} to initialize the mock server if it is present as a system property. - */ @BeforeSuite - public void initializeMockServer() { - if (CustomConfiguration.mockServerAddress != null) { - MockContext.initializeMockServerClient(); - } + public void initializeGlobalConfigurations() { + logger().info("Initialize global configurations"); } - /** - * Tells {@link MockContext} to reset the mock server data if it is present as a system property. - */ @AfterSuite - public void teardownMockServer() { - if (CustomConfiguration.mockServerAddress != null) { - MockContext.resetMockServerClient(); - } + public void teardownGlobalConfigurations() { + logger().info("Teardown global configurations"); } -#end } diff --git a/src/main/resources/archetype-resources/src/test/java/base/MockContext.java b/src/main/resources/archetype-resources/src/test/java/base/MockContext.java index 2a8d82b..08cb349 100644 --- a/src/main/resources/archetype-resources/src/test/java/base/MockContext.java +++ b/src/main/resources/archetype-resources/src/test/java/base/MockContext.java @@ -4,26 +4,24 @@ import ${package}.utils.config.CustomConfiguration; /** - * Context for objects for mocking purposes. + * Holds methods that allow mock external dependency services. */ public class MockContext { private static MockServerClient mockServerClient; /** - * Initializes the mock server client based on {@link CustomConfiguration} settings. + * Instantiates {@link #mockServerClient} object if it needs to be instantiated. + *
+ * Synchronized enssures the singleton client instance. + * + * @return mock server client instance */ - public static void initializeMockServerClient() { - MockContext.mockServerClient = new MockServerClient( - getMockServerHost(), - getMockServerPort()); - } - - public static void resetMockServerClient() { - mockServerClient.reset(); - } + public static synchronized MockServerClient getMockServerClient() { + if (mockServerClient == null) { + mockServerClient = new MockServerClient(getMockServerHost(), getMockServerPort()); + } - public static MockServerClient getMockServerClient() { return mockServerClient; }