Skip to content

Commit

Permalink
Update to Guava 23.0 to match the Selenium dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Sep 23, 2017
1 parent 222c2c5 commit a41a75f
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ junitVersion = 4.12
hamcrestVersion = 1.3
springVersion = 4.3.10.RELEASE
springBootVersion = 1.5.6.RELEASE
guavaVersion = 22.0
guavaVersion = 23.0
restAssuredVersion = 3.0.2
mockitoCoreVersion = 1.10.19
jbehaveCoreVersion = 4.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ public PageObjectWithFullUrlDefinition(WebDriver driver) {
super(driver);
}
}

@DefaultUrl("http://test.myapp.org/somepage")
final class PageObjectWithFullUrlAndPageDefinition extends PageObject {
public PageObjectWithFullUrlAndPageDefinition(WebDriver driver) {
super(driver);
}
}


@DefaultUrl("http://test.myapp.org:9000/somepage")
final class PageObjectWithFullUrlAndPageAndPortDefinition extends PageObject {
Expand Down Expand Up @@ -125,6 +119,13 @@ public PageObjectWithNoUrlDefinition(WebDriver driver) {
}
}

@DefaultUrl("http://test.myapp.org/somepage")
final class PageObjectWithFullUrlAndPageDefinition extends PageObject {
PageObjectWithFullUrlAndPageDefinition(WebDriver driver) {
super(driver);
}
}

@Test
public void the_webdriver_base_url_system_property_should_not_override_pages() {
PageObject page = new PageObjectWithFullUrlAndPageDefinition(webdriver);
Expand All @@ -137,6 +138,18 @@ public void the_webdriver_base_url_system_property_should_not_override_pages() {
verify(webdriver).get("http://staging.myapp.org/somepage");
}

@Test
public void the_webdriver_base_url_system_property_should_allow_sub_domains() {
PageObject page = new PageObjectWithFullUrlAndPageDefinition(webdriver);
PageUrls pageUrls = new PageUrls(page, configuration);
page.setPageUrls(pageUrls);

environmentVariables.setProperty("webdriver.base.url","http://staging.myapp.org/somewhere");
page.open();

verify(webdriver).get("http://staging.myapp.org/somewhere/somepage");
}

@Test
public void the_webdriver_base_url_should_conserve_trailing_slashes() {
PageObject page = new PageObjectWithAURrlWithATrainingSlash(webdriver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
@RunWith(MockitoJUnitRunner.class)
public class WhenUsingAProvidedDriver {


@Mock
WebDriverFactory factory;

MockWebDriverFacade facade;

static class MyDriverSource implements DriverSource {
Expand All @@ -38,7 +34,7 @@ public boolean takesScreenshots() {

class MockWebDriverFacade extends WebDriverFacade {
MockWebDriverFacade(EnvironmentVariables environmentVariables) {
super(ProvidedDriver.class, factory, environmentVariables);
super(ProvidedDriver.class, new WebDriverFactory(environmentVariables), environmentVariables);
}
}

Expand All @@ -52,7 +48,14 @@ public void setup() {
}

@Test
public void the_web_driver_facade_should_expose_the_proxied_driver_class() {
public void the_web_driver_facade_should_expose_the_proxied_driver_class_for_an_uninstantiated_driver() {
Assert.assertEquals(facade.getDriverClass(), HtmlUnitDriver.class);
}

@Test
public void the_web_driver_facade_should_expose_the_proxied_driver_class_for_an_instantiated_driver() {
facade.getProxiedDriver();
Assert.assertEquals(facade.getDriverClass(), HtmlUnitDriver.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ protected void runChild(FrameworkMethod method, RunNotifier notifier) {
TestMethodConfiguration theMethod = TestMethodConfiguration.forMethod(method);

clearMetadataIfRequired();
resetStepLibrariesIfRequired();

if(!failureRerunner.hasToRunTest(method.getDeclaringClass().getCanonicalName(),method.getMethod().getName()))
{
Expand Down Expand Up @@ -501,6 +502,12 @@ private void clearMetadataIfRequired() {
}
}

private void resetStepLibrariesIfRequired() {
if (theTest.shouldResetStepLibraries()) {
stepFactory.reset();
}
}

protected void additionalBrowserCleanup() {
// Template method. Override this to do additional cleanup e.g. killing IE processes.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public boolean shouldClearTheBrowserSession() {
return (isAWebTest() && TestCaseAnnotations.shouldClearCookiesBeforeEachTestIn(testClass().getJavaClass()));
}

public boolean shouldResetStepLibraries() {
return !TestCaseAnnotations.shouldUsePersistantStepLibraries(testClass);
}

public static class TestConfigurationBuilder {

private final Class<?> testClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package net.serenitybdd.junit.runners.smoketests;

import net.serenitybdd.junit.runners.SerenityRunner;
import net.thucydides.core.annotations.Step;
import net.thucydides.core.annotations.Steps;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;

@RunWith(SerenityRunner.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
/**
* Smoke tests to demonstrate how step libraries work. Intended to be run as a whole test, not individually (order is important).
*/
public class WhenInstantiatingStepLibraries {

public static class SomeStepLibrary {

public int stepsRun = 0;

@Step
public void doSomething() {
stepsRun++;
}

@Step
public void doSomethingElse() {
stepsRun++;
}

@Step
public void doSomeOtherThing() {
stepsRun++;
}

}

@Steps
SomeStepLibrary someStepLibrary;

@Steps
SomeStepLibrary anotherStepLibrary;

// @Steps(uniqueInstance = true)
// SomeStepLibrary aUniqueStepLibrary;
//
// @Steps(uniqueInstance = true)
// SomeStepLibrary anotherUniqueStepLibrary;

@Test
public void example_1_serenity_injects_step_library_fields_that_are_annotated_with_the_Steps_annotation() {
assertThat(someStepLibrary, notNullValue());
assertThat(anotherStepLibrary, notNullValue());
}

@Test
public void example_2_you_can_maintain_state_in_the_step_library_within_a_test_() {

someStepLibrary.doSomething();
someStepLibrary.doSomethingElse();

assertThat(someStepLibrary.stepsRun, equalTo(2));
}

@Test
public void example_3_tests_reset_the_step_libraries_before_each_test() {

assertThat(someStepLibrary.stepsRun, equalTo(0));

someStepLibrary.doSomeOtherThing();

assertThat(someStepLibrary.stepsRun, equalTo(1));
}

@Test
public void example_4_you_can_have_several_step_libararies_of_the_same_type_in_a_test() {

someStepLibrary.stepsRun = 0;
anotherStepLibrary.stepsRun = 0;

someStepLibrary.doSomething();

anotherStepLibrary.doSomething();
anotherStepLibrary.doSomethingElse();

assertThat(someStepLibrary.stepsRun, equalTo(1));
assertThat(anotherStepLibrary.stepsRun, equalTo(2));
}

// @Test
// public void example_5_unique_step_libraries_maintain_their_own_state() {
//
// aUniqueStepLibrary.doSomething();
// aUniqueStepLibrary.doSomeOtherThing();
//
// anotherUniqueStepLibrary.doSomethingElse();
//
// assertThat(aUniqueStepLibrary.stepsRun, equalTo(2));
// assertThat(anotherUniqueStepLibrary.stepsRun, equalTo(1));
// }

}

0 comments on commit a41a75f

Please sign in to comment.