Skip to content

Commit

Permalink
Optimised the timeout test
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Sep 27, 2016
1 parent f75fcdd commit 676f41d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ private String nameOf(WebDriver driver) {
if (driver instanceof WebDriverFacade) {
return ((WebDriverFacade) driver).getDriverName();
}
if (driver instanceof RemoteWebDriver) {
return ((RemoteWebDriver) driver).getCapabilities().getBrowserName();
}
return driver.toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package net.thucydides.core.webdriver;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileDriver;
import org.openqa.selenium.WebDriver;

public class WebDriverType {
public static boolean isMobile(WebDriver driver) {
if(driver instanceof WebDriverFacade){
return ((WebDriverFacade)driver).getDriverClass().isAssignableFrom(AppiumDriver.class);
return (MobileDriver.class.isAssignableFrom(((WebDriverFacade) driver).getDriverClass()));
}
return (driver.getClass().isAssignableFrom(AppiumDriver.class));
return (driver instanceof MobileDriver);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import net.thucydides.core.steps.ExecutedStepDescription
import net.thucydides.core.steps.StepEventBus
import net.thucydides.core.steps.StepFailure
import net.thucydides.core.util.MockEnvironmentVariables
import net.thucydides.core.util.SystemEnvironmentVariables
import net.thucydides.core.webdriver.SerenityWebdriverManager
import net.thucydides.core.webdriver.WebDriverFacade
import net.thucydides.core.webdriver.WebDriverFactory
Expand All @@ -15,11 +16,11 @@ import net.thucydides.core.webdriver.exceptions.ElementShouldBeInvisibleExceptio
import org.openqa.selenium.By
import org.openqa.selenium.NoSuchElementException
import org.openqa.selenium.TimeoutException
import org.openqa.selenium.phantomjs.PhantomJSDriver
import spock.lang.Ignore
import spock.lang.Specification
import spock.lang.Timeout
import spock.lang.Unroll
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriverService
import org.openqa.selenium.remote.DesiredCapabilities
import org.openqa.selenium.remote.RemoteWebDriver
import spock.lang.*

import java.util.concurrent.TimeUnit

Expand All @@ -38,14 +39,39 @@ import static java.util.concurrent.TimeUnit.SECONDS
*/
class WhenManagingWebdriverTimeouts extends Specification {

WebDriver driver

@Shared ChromeDriverService chromeDriverService;

def setupSpec() {
chromeDriverService = new ChromeDriverService.Builder()
.usingAnyFreePort()
.build();
chromeDriverService.start()
}

def cleanupSpec() {
chromeDriverService.stop()
}

def setup() {
StepEventBus.eventBus.clear()
driver = null
}

def cleanup() {
SerenityWebdriverManager.inThisTestThread().closeAllDrivers();
if (driver) {
driver.quit();
}
}

public WebDriver newDriver() {
driver = new RemoteWebDriver(chromeDriverService.getUrl(), DesiredCapabilities.chrome());
return driver
}


//
// IMPLICIT WAITS
//
Expand Down Expand Up @@ -80,14 +106,16 @@ class WhenManagingWebdriverTimeouts extends Specification {
for(String key : variables.keySet()) {
environmentVariables.setProperty(key, variables[key]);
}
def driver = new WebDriverFacade(PhantomJSDriver.class, new WebDriverFactory(), environmentVariables); // HtmlUnitDriver();
def page = new StaticSitePage(driver, environmentVariables)
WebDriverFacade driverFacade = new WebDriverFacade(newDriver(), new WebDriverFactory(), environmentVariables);
def page = new StaticSitePage(driverFacade, environmentVariables)
page.open()
return page
}

private StaticSitePage openStaticPage() {
def driver = new WebDriverFacade(PhantomJSDriver.class, new WebDriverFactory()); // HtmlUnitDriver();
// def page = new StaticSitePage(newDriver())
// driver = new WebDriverFacade(ChromeDriver.class, new WebDriverFactory()); // HtmlUnitDriver();
def driver = new WebDriverFacade(newDriver(), new WebDriverFactory(), new SystemEnvironmentVariables()); // HtmlUnitDriver();
def page = new StaticSitePage(driver)
page.open()
return page
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/static-site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
}

function displayFieldsAfterDelay() {
setTimeout("loadElementsSelect()", 3000);
setTimeout("loadElementsSelect()", 5000);
setTimeout("displayCityField()", 1500);
setTimeout("displayCountryField()", 1500);
setTimeout("displaySlowLoaderField()", 4000);
setTimeout("displaySlowLoaderField()", 5000);
setTimeout("displayVerySlowLoadingField()", 60000);
setTimeout("hideLocationTitle()", 2000);
setTimeout("activateDisabledButton()", 2000);
Expand Down

0 comments on commit 676f41d

Please sign in to comment.