From feaae625ca052d1c0dc6e01357714312a45a1248 Mon Sep 17 00:00:00 2001 From: bluurr Date: Mon, 10 Jun 2019 19:47:38 +0100 Subject: [PATCH 1/6] Bug correction to support a login header with multiple classes. --- src/main/java/com/bluurr/quora/page/LoginPage.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bluurr/quora/page/LoginPage.java b/src/main/java/com/bluurr/quora/page/LoginPage.java index 67493c3..72777dc 100644 --- a/src/main/java/com/bluurr/quora/page/LoginPage.java +++ b/src/main/java/com/bluurr/quora/page/LoginPage.java @@ -57,8 +57,8 @@ public static LoginPage open(final URI location) @FindBy(xpath="//input[contains(@class, 'submit_button') and @value = 'Login']") private WebElement submitButton; - - @FindBy(className="LoggedInSiteHeader") + + @FindBy(xpath="//*[contains(@class, 'LoggedInSiteHeader')]") private List loginHeader; @FindBy(xpath="//*[@class='regular_login']//*[@class='input_validation_error_text']") From a8b625e3a97085ca97114bb6efbbd623280f63a8 Mon Sep 17 00:00:00 2001 From: bluurr Date: Mon, 10 Jun 2019 21:27:12 +0100 Subject: [PATCH 2/6] Updated tests to use junit 5. --- pom.xml | 36 ++++++++++++++---- .../bluurr/quora/it/BaseIntegrationTest.java | 34 ++++++++--------- .../bluurr/quora/it/page/DashBoardPageIT.java | 32 ++++++++-------- .../com/bluurr/quora/it/page/LoginPageIT.java | 12 +++--- .../bluurr/quora/it/page/QuestionPageIT.java | 14 +++---- .../bluurr/quora/it/page/SearchPageIT.java | 37 +++++++++---------- 6 files changed, 92 insertions(+), 73 deletions(-) diff --git a/pom.xml b/pom.xml index 2c38090..a50dd12 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.bluurr quora_loader - 1.4.0 + 1.5.0 ${project.groupId}:${project.artifactId} A realtime read-only locator and extraction library for Quora questions and answers. https://github.com/bluurr/QuoraLoader/ @@ -31,8 +31,8 @@ 1.8 1.8 - 5.1.5.RELEASE - 1.18.6 + 5.1.7.RELEASE + 1.18.8 @@ -47,7 +47,7 @@ org.seleniumhq.selenium selenium-java - 3.8.1 + 3.141.59 @@ -59,7 +59,7 @@ com.github.webdriverextensions webdriverextensions - 3.10.0 + 3.11.0 @@ -86,7 +86,7 @@ org.slf4j slf4j-api - 1.7.25 + 1.7.26 @@ -106,7 +106,14 @@ org.junit.jupiter junit-jupiter-api - 5.4.0 + 5.4.2 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.4.2 test @@ -115,12 +122,25 @@ hamcrest-junit 2.0.0.0 test + + + junit + junit + + org.testcontainers selenium - 1.10.6 + 1.11.3 + test + + + + org.testcontainers + junit-jupiter + 1.11.3 test diff --git a/src/test/java/com/bluurr/quora/it/BaseIntegrationTest.java b/src/test/java/com/bluurr/quora/it/BaseIntegrationTest.java index 40ef161..4ff3946 100644 --- a/src/test/java/com/bluurr/quora/it/BaseIntegrationTest.java +++ b/src/test/java/com/bluurr/quora/it/BaseIntegrationTest.java @@ -1,41 +1,41 @@ package com.bluurr.quora.it; -import java.net.URI; - -import javax.annotation.Resource; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.runner.RunWith; +import com.bluurr.quora.extension.BotExtra; +import com.bluurr.quora.it.config.IntegrationConfig; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.testcontainers.containers.BrowserWebDriverContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; -import com.bluurr.quora.extension.BotExtra; -import com.bluurr.quora.it.config.IntegrationConfig; +import javax.annotation.Resource; +import java.net.URI; /** * * @author Bluurr * */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) +@Testcontainers @ContextConfiguration(classes=IntegrationConfig.class) public abstract class BaseIntegrationTest { public static final URI QUORA_HOST = URI.create("https://www.quora.com"); - + @Resource - @Rule - public BrowserWebDriverContainer driverContainer; + @Container + private BrowserWebDriverContainer driverContainer; - @Before + @BeforeEach public void beforeTest() { driverContainer.getWebDriver().manage().deleteAllCookies(); BotExtra.setDriver(driverContainer.getWebDriver()); } - @After + @AfterEach public void afterTest() { BotExtra.closeDriver(); } diff --git a/src/test/java/com/bluurr/quora/it/page/DashBoardPageIT.java b/src/test/java/com/bluurr/quora/it/page/DashBoardPageIT.java index 4bd7f94..6eefc4f 100644 --- a/src/test/java/com/bluurr/quora/it/page/DashBoardPageIT.java +++ b/src/test/java/com/bluurr/quora/it/page/DashBoardPageIT.java @@ -1,26 +1,26 @@ package com.bluurr.quora.it.page; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; - -import javax.annotation.Resource; - -import org.junit.Before; -import org.junit.Test; - import com.bluurr.quora.domain.LoginCredential; import com.bluurr.quora.it.BaseIntegrationTest; import com.bluurr.quora.page.DashBoardPage; import com.bluurr.quora.page.LoginPage; import com.bluurr.quora.page.search.SearchPage; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import javax.annotation.Resource; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; /** * * @author Bluurr * */ -public class DashBoardPageIT extends BaseIntegrationTest { +class DashBoardPageIT extends BaseIntegrationTest { /** * Likely to always return topics. */ @@ -29,21 +29,21 @@ public class DashBoardPageIT extends BaseIntegrationTest { @Resource private LoginCredential credential; - @Before - public void before() { + @BeforeEach + void before() { LoginPage.open(QUORA_HOST).login(credential); } @Test - public void performSearch() { + void performSearch() { DashBoardPage dashboard = DashBoardPage.open(); SearchPage page = dashboard.search(SEARCH_TERM); assertThat(page, is(notNullValue())); } - @Test(expected=IllegalArgumentException.class) - public void performInvalidSearch() { + @Test + void performInvalidSearch() { DashBoardPage dashboard = DashBoardPage.open(); - dashboard.search(""); + Assertions.assertThrows(IllegalArgumentException.class, () -> dashboard.search("")); } } diff --git a/src/test/java/com/bluurr/quora/it/page/LoginPageIT.java b/src/test/java/com/bluurr/quora/it/page/LoginPageIT.java index 4418433..53ac8ed 100644 --- a/src/test/java/com/bluurr/quora/it/page/LoginPageIT.java +++ b/src/test/java/com/bluurr/quora/it/page/LoginPageIT.java @@ -5,24 +5,24 @@ import javax.annotation.Resource; -import org.junit.Test; - import com.bluurr.quora.domain.LoginCredential; import com.bluurr.quora.it.BaseIntegrationTest; import com.bluurr.quora.page.InvalidLoginException; import com.bluurr.quora.page.LoginPage; +import org.junit.jupiter.api.Test; /** * * @author Bluurr * */ -public class LoginPageIT extends BaseIntegrationTest { +class LoginPageIT extends BaseIntegrationTest { + @Resource private LoginCredential credential; @Test - public void testValidLogin() { + void testValidLogin() { assertThat(LoginPage.isLoggedIn(), is(false)); LoginPage.open(QUORA_HOST).login(credential); @@ -30,8 +30,8 @@ public void testValidLogin() { assertThat(LoginPage.isLoggedIn(), is(true)); } - @Test(expected=InvalidLoginException.class) - public void testInvalidLogin() { + @Test//(expected=InvalidLoginException.class) + void testInvalidLogin() { assertThat(LoginPage.isLoggedIn(), is(false)); LoginPage.open(QUORA_HOST).login(createInvalidLogin()); diff --git a/src/test/java/com/bluurr/quora/it/page/QuestionPageIT.java b/src/test/java/com/bluurr/quora/it/page/QuestionPageIT.java index 9fe6220..c0fd5dd 100644 --- a/src/test/java/com/bluurr/quora/it/page/QuestionPageIT.java +++ b/src/test/java/com/bluurr/quora/it/page/QuestionPageIT.java @@ -6,9 +6,6 @@ import javax.annotation.Resource; import org.hamcrest.core.Every; -import org.junit.Before; -import org.junit.Test; - import com.bluurr.quora.domain.Answer; import com.bluurr.quora.domain.Answers; import com.bluurr.quora.domain.LoginCredential; @@ -18,13 +15,16 @@ import com.bluurr.quora.page.LoginPage; import com.bluurr.quora.page.question.QuestionPage; import com.bluurr.quora.page.search.SearchPage; +import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * * @author Bluurr * */ -public class QuestionPageIT extends BaseIntegrationTest { +class QuestionPageIT extends BaseIntegrationTest { /** * Likely to always return topics. */ @@ -35,14 +35,14 @@ public class QuestionPageIT extends BaseIntegrationTest { private QuestionSummary summary; - @Before - public void before() { + @BeforeEach + void before() { SearchPage page = LoginPage.open(QUORA_HOST).login(credential).search(SEARCH_TERM); summary = page.getQuestions(1).get(0); } @Test - public void loadQuestion() { + void loadQuestion() { QuestionPage page = QuestionPage.open(summary.getLocation()); assertThat(page, notNullValue()); Question question = page.getQuestion(Answers.limit(5)); diff --git a/src/test/java/com/bluurr/quora/it/page/SearchPageIT.java b/src/test/java/com/bluurr/quora/it/page/SearchPageIT.java index 5ceb689..02ebabc 100644 --- a/src/test/java/com/bluurr/quora/it/page/SearchPageIT.java +++ b/src/test/java/com/bluurr/quora/it/page/SearchPageIT.java @@ -1,28 +1,27 @@ package com.bluurr.quora.it.page; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; - -import java.util.List; - -import javax.annotation.Resource; - -import org.hamcrest.core.Every; -import org.junit.Before; -import org.junit.Test; - import com.bluurr.quora.domain.LoginCredential; import com.bluurr.quora.domain.QuestionSummary; import com.bluurr.quora.it.BaseIntegrationTest; import com.bluurr.quora.page.LoginPage; import com.bluurr.quora.page.search.SearchPage; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import javax.annotation.Resource; +import java.util.List; + +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Every.everyItem; /** * * @author Bluurr * */ -public class SearchPageIT extends BaseIntegrationTest { +class SearchPageIT extends BaseIntegrationTest { /** * Likely to always return topics. */ @@ -32,23 +31,23 @@ public class SearchPageIT extends BaseIntegrationTest { @Resource private LoginCredential credential; - @Before - public void before() { + @BeforeEach + void before() { LoginPage.open(QUORA_HOST).login(credential); } @Test - public void performSearch() { + void performSearch() { SearchPage page = SearchPage.openDirect(SEARCH_TERM, SEARCH_TYPE); assertThat(page, notNullValue()); List questions = page.getQuestions(5); assertThat(questions, notNullValue()); - assertThat(questions, Every.everyItem(notNullValue(QuestionSummary.class))); + assertThat(questions, everyItem(notNullValue(QuestionSummary.class))); } - @Test(expected=IllegalArgumentException.class) - public void performInvalidSearch() { - SearchPage.openDirect("", SEARCH_TYPE); + @Test + void performInvalidSearch() { + Assertions.assertThrows(IllegalArgumentException.class, () -> SearchPage.openDirect("", SEARCH_TYPE)); } } From 3bef78645cde17d8c138acd6e45702b757d38ed3 Mon Sep 17 00:00:00 2001 From: bluurr Date: Mon, 10 Jun 2019 22:09:13 +0100 Subject: [PATCH 3/6] Updated to use headless mode by default (This works much better when running all the tests) --- .../bluurr/quora/it/BaseIntegrationTest.java | 5 ++--- .../quora/it/config/IntegrationConfig.java | 13 ++++++----- .../com/bluurr/quora/it/page/LoginPageIT.java | 20 +++++++---------- .../bluurr/quora/it/page/QuestionPageIT.java | 22 +++++++------------ 4 files changed, 25 insertions(+), 35 deletions(-) diff --git a/src/test/java/com/bluurr/quora/it/BaseIntegrationTest.java b/src/test/java/com/bluurr/quora/it/BaseIntegrationTest.java index 4ff3946..56fdc7a 100644 --- a/src/test/java/com/bluurr/quora/it/BaseIntegrationTest.java +++ b/src/test/java/com/bluurr/quora/it/BaseIntegrationTest.java @@ -23,15 +23,14 @@ @Testcontainers @ContextConfiguration(classes=IntegrationConfig.class) public abstract class BaseIntegrationTest { - public static final URI QUORA_HOST = URI.create("https://www.quora.com"); + protected static final URI QUORA_HOST = URI.create("https://www.quora.com"); @Resource @Container private BrowserWebDriverContainer driverContainer; - + @BeforeEach public void beforeTest() { - driverContainer.getWebDriver().manage().deleteAllCookies(); BotExtra.setDriver(driverContainer.getWebDriver()); } diff --git a/src/test/java/com/bluurr/quora/it/config/IntegrationConfig.java b/src/test/java/com/bluurr/quora/it/config/IntegrationConfig.java index abc36eb..4ebd23b 100644 --- a/src/test/java/com/bluurr/quora/it/config/IntegrationConfig.java +++ b/src/test/java/com/bluurr/quora/it/config/IntegrationConfig.java @@ -1,16 +1,17 @@ package com.bluurr.quora.it.config; -import java.io.File; - +import com.bluurr.quora.domain.LoginCredential; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.DesiredCapabilities; import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; import org.testcontainers.containers.BrowserWebDriverContainer; import org.testcontainers.containers.BrowserWebDriverContainer.VncRecordingMode; -import com.bluurr.quora.domain.LoginCredential; +import java.io.File; /** * @@ -26,7 +27,7 @@ public LoginCredential createLogin(final @Value("${quora.login.username}") Strin } @Bean - public ChromeOptions createOptions(final @Value("${webdriver.headless:false}") boolean headless, + public ChromeOptions createOptions(final @Value("${webdriver.headless:true}") boolean headless, final @Value("${quora.contact}") String contactEmail) { ChromeOptions options = new ChromeOptions(); options.setHeadless(headless); @@ -37,9 +38,9 @@ public ChromeOptions createOptions(final @Value("${webdriver.headless:false}") b return options; } - - @SuppressWarnings("resource") + @Bean + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public BrowserWebDriverContainer createDriverContainer(final ChromeOptions options, final @Value("${container.record:false}") boolean record) { BrowserWebDriverContainer container = new BrowserWebDriverContainer<>(). withCapabilities(new DesiredCapabilities(options)); diff --git a/src/test/java/com/bluurr/quora/it/page/LoginPageIT.java b/src/test/java/com/bluurr/quora/it/page/LoginPageIT.java index 53ac8ed..4fd2d88 100644 --- a/src/test/java/com/bluurr/quora/it/page/LoginPageIT.java +++ b/src/test/java/com/bluurr/quora/it/page/LoginPageIT.java @@ -1,16 +1,17 @@ package com.bluurr.quora.it.page; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; - -import javax.annotation.Resource; - import com.bluurr.quora.domain.LoginCredential; import com.bluurr.quora.it.BaseIntegrationTest; import com.bluurr.quora.page.InvalidLoginException; import com.bluurr.quora.page.LoginPage; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import javax.annotation.Resource; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + /** * * @author Bluurr @@ -24,19 +25,14 @@ class LoginPageIT extends BaseIntegrationTest { @Test void testValidLogin() { assertThat(LoginPage.isLoggedIn(), is(false)); - LoginPage.open(QUORA_HOST).login(credential); - assertThat(LoginPage.isLoggedIn(), is(true)); } - @Test//(expected=InvalidLoginException.class) + @Test void testInvalidLogin() { assertThat(LoginPage.isLoggedIn(), is(false)); - - LoginPage.open(QUORA_HOST).login(createInvalidLogin()); - - assertThat(LoginPage.isLoggedIn(), is(false)); + Assertions.assertThrows(InvalidLoginException.class, () -> LoginPage.open(QUORA_HOST).login(createInvalidLogin())); } private LoginCredential createInvalidLogin() { diff --git a/src/test/java/com/bluurr/quora/it/page/QuestionPageIT.java b/src/test/java/com/bluurr/quora/it/page/QuestionPageIT.java index c0fd5dd..0d8781c 100644 --- a/src/test/java/com/bluurr/quora/it/page/QuestionPageIT.java +++ b/src/test/java/com/bluurr/quora/it/page/QuestionPageIT.java @@ -1,24 +1,19 @@ package com.bluurr.quora.it.page; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; - -import javax.annotation.Resource; - -import org.hamcrest.core.Every; -import com.bluurr.quora.domain.Answer; -import com.bluurr.quora.domain.Answers; -import com.bluurr.quora.domain.LoginCredential; -import com.bluurr.quora.domain.Question; -import com.bluurr.quora.domain.QuestionSummary; +import com.bluurr.quora.domain.*; import com.bluurr.quora.it.BaseIntegrationTest; import com.bluurr.quora.page.LoginPage; import com.bluurr.quora.page.question.QuestionPage; import com.bluurr.quora.page.search.SearchPage; -import org.junit.Before; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import javax.annotation.Resource; + +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Every.everyItem; + /** * * @author Bluurr @@ -48,7 +43,6 @@ void loadQuestion() { Question question = page.getQuestion(Answers.limit(5)); assertThat(question, notNullValue()); assertThat(question.getAnswers(), notNullValue()); - assertThat(question.getAnswers(), Every.everyItem(notNullValue(Answer.class))); + assertThat(question.getAnswers(), everyItem(notNullValue(Answer.class))); } - } From 64e7f89d7d3bb16fe8b0aed74d5bf47a23e0d2da Mon Sep 17 00:00:00 2001 From: bluurr Date: Mon, 10 Jun 2019 22:16:00 +0100 Subject: [PATCH 4/6] Updated to use hamcrest-library instead of hamcrest-junit as hamcrest-junit is abandoned. --- pom.xml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index a50dd12..cda5ea1 100644 --- a/pom.xml +++ b/pom.xml @@ -119,15 +119,9 @@ org.hamcrest - hamcrest-junit - 2.0.0.0 + hamcrest-library + 2.1 test - - - junit - junit - - From 4e9644066f21a6dc0d1ddb268e26d634bb5fd2cd Mon Sep 17 00:00:00 2001 From: bluurr Date: Sun, 30 Jun 2019 20:15:42 +0100 Subject: [PATCH 5/6] Increased max wait time from 3 seconds to 10 second to better handle slower connections. --- src/main/java/com/bluurr/quora/page/DashBoardPage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/bluurr/quora/page/DashBoardPage.java b/src/main/java/com/bluurr/quora/page/DashBoardPage.java index b439d4d..1e5963a 100644 --- a/src/main/java/com/bluurr/quora/page/DashBoardPage.java +++ b/src/main/java/com/bluurr/quora/page/DashBoardPage.java @@ -21,7 +21,7 @@ public static DashBoardPage open() { return dashboard; } - private static final int MAX_WAIT_SECONDS = 3; + private static final int MAX_WAIT_SECONDS = 10; @FindBy(xpath="//*[contains(@class, 'selector_input') and @placeholder = 'Search Quora']") private WebElement searchBar; From 1b001dbe526d3cf914892bbb97324212b1a59752 Mon Sep 17 00:00:00 2001 From: bluurr Date: Sun, 30 Jun 2019 20:22:17 +0100 Subject: [PATCH 6/6] Maven version bump in the readme.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c31dff6..470895f 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ To add a dependency on Quora loader using Maven, use the following: com.bluurr quora_loader - 1.4.0 + 1.5.0 ```