Skip to content

Commit

Permalink
Merge pull request #5 from bluurr/feature/junit5-correction-to-login
Browse files Browse the repository at this point in the history
Feature/junit5 correction to login
  • Loading branch information
bluurr authored Jun 30, 2019
2 parents 11432a4 + 1b001db commit 381edac
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 112 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ To add a dependency on Quora loader using Maven, use the following:
<dependency>
<groupId>com.bluurr</groupId>
<artifactId>quora_loader</artifactId>
<version>1.4.0</version>
<version>1.5.0</version>
</dependency>
```

Expand Down
34 changes: 24 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.bluurr</groupId>
<artifactId>quora_loader</artifactId>
<version>1.4.0</version>
<version>1.5.0</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>A realtime read-only locator and extraction library for Quora questions and answers.</description>
<url>https://github.com/bluurr/QuoraLoader/</url>
Expand Down Expand Up @@ -31,8 +31,8 @@
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.lib.spring.version>5.1.5.RELEASE</project.lib.spring.version>
<project.lombok.version>1.18.6</project.lombok.version>
<project.lib.spring.version>5.1.7.RELEASE</project.lib.spring.version>
<project.lombok.version>1.18.8</project.lombok.version>
</properties>

<dependencies>
Expand All @@ -47,7 +47,7 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.8.1</version>
<version>3.141.59</version>
</dependency>

<dependency>
Expand All @@ -59,7 +59,7 @@
<dependency>
<groupId>com.github.webdriverextensions</groupId>
<artifactId>webdriverextensions</artifactId>
<version>3.10.0</version>
<version>3.11.0</version>
<exclusions>
<!-- Moved to test scope. -->
<exclusion>
Expand All @@ -86,7 +86,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
<version>1.7.26</version>
</dependency>

<dependency>
Expand All @@ -106,21 +106,35 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.0</version>
<version>5.4.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-junit</artifactId>
<version>2.0.0.0</version>
<artifactId>hamcrest-library</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>selenium</artifactId>
<version>1.10.6</version>
<version>1.11.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.11.3</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/bluurr/quora/page/DashBoardPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/bluurr/quora/page/LoginPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,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<WebElement> loginHeader;

@FindBy(xpath="//*[@class='regular_login']//*[@class='input_validation_error_text']")
Expand Down
39 changes: 19 additions & 20 deletions src/test/java/com/bluurr/quora/it/BaseIntegrationTest.java
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
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");
protected static final URI QUORA_HOST = URI.create("https://www.quora.com");

@Resource
@Rule
public BrowserWebDriverContainer<?> driverContainer;
@Before
@Container
private BrowserWebDriverContainer<?> driverContainer;

@BeforeEach
public void beforeTest() {
driverContainer.getWebDriver().manage().deleteAllCookies();
BotExtra.setDriver(driverContainer.getWebDriver());
}

@After
@AfterEach
public void afterTest() {
BotExtra.closeDriver();
}
Expand Down
13 changes: 7 additions & 6 deletions src/test/java/com/bluurr/quora/it/config/IntegrationConfig.java
Original file line number Diff line number Diff line change
@@ -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;

/**
*
Expand All @@ -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);
Expand All @@ -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));
Expand Down
32 changes: 16 additions & 16 deletions src/test/java/com/bluurr/quora/it/page/DashBoardPageIT.java
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand All @@ -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(""));
}
}
30 changes: 13 additions & 17 deletions src/test/java/com/bluurr/quora/it/page/LoginPageIT.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,38 @@
package com.bluurr.quora.it.page;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

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.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
*
*/
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);

assertThat(LoginPage.isLoggedIn(), is(true));
}

@Test(expected=InvalidLoginException.class)
public void testInvalidLogin() {
assertThat(LoginPage.isLoggedIn(), is(false));

LoginPage.open(QUORA_HOST).login(createInvalidLogin());

@Test
void testInvalidLogin() {
assertThat(LoginPage.isLoggedIn(), is(false));
Assertions.assertThrows(InvalidLoginException.class, () -> LoginPage.open(QUORA_HOST).login(createInvalidLogin()));
}

private LoginCredential createInvalidLogin() {
Expand Down
Loading

0 comments on commit 381edac

Please sign in to comment.