Skip to content

Commit

Permalink
Serving pages from GH Pages instead of Jetty
Browse files Browse the repository at this point in the history
  • Loading branch information
vania-pooh committed Mar 30, 2017
1 parent 7a0e015 commit f3bb845
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 155 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 0 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<properties>
<compiler.version>1.8</compiler.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.version>9.4.2.v20170220</jetty.version>
<selenium.version>2.53.1</selenium.version>
<properties.version>2.0.RC6</properties.version>
<allure.version>1.5.2</allure.version>
Expand All @@ -22,16 +21,6 @@
</properties>

<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/com/aerokube/selenoid/TestProxy.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.aerokube.selenoid;

import com.aerokube.selenoid.misc.Page;
import com.aerokube.selenoid.misc.TestBase;
import net.lightbody.bmp.BrowserMobProxy;
import net.lightbody.bmp.BrowserMobProxyServer;
Expand All @@ -10,8 +11,6 @@
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import ru.yandex.qatools.allure.annotations.Features;
import com.aerokube.selenoid.misc.JettyRule;
import com.aerokube.selenoid.misc.Page;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -91,7 +90,7 @@ private DesiredCapabilities getProxyCapabilities(DesiredCapabilities caps) {
}

private String getProxyString() {
return String.format("%s:%d", JettyRule.getHostName(), proxy.getPort());
return String.format("%s:%d", getHostName(), proxy.getPort());
}

}
100 changes: 0 additions & 100 deletions src/test/java/com/aerokube/selenoid/misc/JettyRule.java

This file was deleted.

42 changes: 14 additions & 28 deletions src/test/java/com/aerokube/selenoid/misc/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@

import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.function.Function;

public abstract class TestBase {
Expand All @@ -23,9 +20,6 @@ public abstract class TestBase {
@Rule
public WebDriverRule webDriverRule;

@Rule
public JettyRule jettyRule = new JettyRule();

public TestBase() {
this.webDriverRule = new WebDriverRule(getCapabilitiesProcessor());
}
Expand All @@ -35,28 +29,11 @@ public WebDriver getDriver() {
}

public void openPage(Page page) throws Exception {
String pageUrl = getPageUrl(page);
String pageUrl = webDriverRule.getPageUrl(page);
LOG.info(String.format("Opening page at: %s", pageUrl));
ExecutorService executor = Executors.newSingleThreadExecutor();
try {
Future<?> future = executor.submit(() -> {
getDriver().get(pageUrl);
});
future.get(10, TimeUnit.SECONDS);
} catch (Exception e) {
LOG.info(String.format("Failed to open page at: %s", pageUrl));
} finally {
if (!executor.isTerminated()) {
executor.shutdownNow();
}
}
getDriver().get(pageUrl);
}

private String getPageUrl(Page page) throws Exception {
String file = String.format("/%s", page.getName());
return new URL("http", JettyRule.getHostName(), jettyRule.getPort(), file).toString();
}

public void fail(String message, Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Expand All @@ -73,5 +50,14 @@ public void fail(String msg) {
protected Function<DesiredCapabilities, DesiredCapabilities> getCapabilitiesProcessor() {
return Function.identity();
}


protected String getHostName() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
LOG.error("Failed to determine host name");
return "localhost";
}
}

}
4 changes: 4 additions & 0 deletions src/test/java/com/aerokube/selenoid/misc/TestProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

interface TestProperties {

@Property("pages.base.url")
@DefaultValue("http://vania-pooh.github.io/selenoid-container-tests/pages/")
String getBaseUrl();

@Property("grid.auth.login")
String getLogin();

Expand Down
33 changes: 20 additions & 13 deletions src/test/java/com/aerokube/selenoid/misc/WebDriverRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

public class WebDriverRule extends ExternalResource {
Expand All @@ -26,22 +27,25 @@ public class WebDriverRule extends ExternalResource {
@Override
protected void before() throws Throwable {
driver = new RemoteWebDriver(getConnectionUrl(), capabilitiesProcessor.apply(getDesiredCapabilities()));
driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
}

private URL getConnectionUrl() throws MalformedURLException {
return areLoginAndPasswordPresent() ?
new URL(String.format(
"http://%s:%s@%s:%s/wd/hub",
PROPERTIES.getLogin(),
PROPERTIES.getPassword(),
PROPERTIES.getHostName(),
PROPERTIES.getHostPort()
)) :
new URL(String.format(
"http://%s:%s/wd/hub",
PROPERTIES.getHostName(),
PROPERTIES.getHostPort()
));
return new URL(
areLoginAndPasswordPresent() ?
String.format(
"http://%s:%s@%s:%s/wd/hub",
PROPERTIES.getLogin(),
PROPERTIES.getPassword(),
PROPERTIES.getHostName(),
PROPERTIES.getHostPort()
) :
String.format(
"http://%s:%s/wd/hub",
PROPERTIES.getHostName(),
PROPERTIES.getHostPort()
)
);
}

private boolean areLoginAndPasswordPresent() {
Expand All @@ -68,4 +72,7 @@ public WebDriver getDriver() {
return driver;
}

String getPageUrl(Page page) {
return String.format("%s/%s", PROPERTIES.getBaseUrl(), page.getName());
}
}

0 comments on commit f3bb845

Please sign in to comment.