-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b3e1da0
Showing
9 changed files
with
471 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Created by http://www.gitignore.io | ||
|
||
### Java ### | ||
*.class | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
|
||
|
||
### Intellij ### | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode | ||
|
||
## Directory-based project format | ||
.idea/ | ||
# if you remove the above rule, at least ignore user-specific stuff: | ||
# .idea/workspace.xml | ||
# .idea/tasks.xml | ||
# and these sensitive or high-churn files: | ||
# .idea/dataSources.ids | ||
# .idea/dataSources.xml | ||
# .idea/sqlDataSources.xml | ||
# .idea/dynamic.xml | ||
|
||
## File-based project format | ||
*.ipr | ||
*.iws | ||
*.iml | ||
|
||
## Additional for IntelliJ | ||
out/ | ||
|
||
# generated by mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# Created by http://www.gitignore.io | ||
|
||
### Eclipse ### | ||
*.pydevproject | ||
.metadata | ||
.gradle | ||
bin/ | ||
tmp/ | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
local.properties | ||
.settings/ | ||
.loadpath | ||
|
||
# External tool builders | ||
.externalToolBuilders/ | ||
|
||
# Locally stored "Eclipse launch configurations" | ||
*.launch | ||
|
||
# CDT-specific | ||
.cproject | ||
|
||
# PDT-specific | ||
.buildpath | ||
|
||
# sbteclipse plugin | ||
.target | ||
|
||
# TeXlipse plugin | ||
.texlipse | ||
|
||
.classpath | ||
.project | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.jprotractor</groupId> | ||
<artifactId>jprotractor</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>jprotractor</name> | ||
<url>http://carlosbecker.com</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.7</maven.compiler.source> | ||
<maven.compiler.target>1.7</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.seleniumhq.selenium</groupId> | ||
<artifactId>selenium-java</artifactId> | ||
<version>2.42.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.seleniumhq.selenium</groupId> | ||
<artifactId>selenium-firefox-driver</artifactId> | ||
<version>2.42.2</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
57 changes: 57 additions & 0 deletions
57
src/main/java/com/jprotractor/JProtractorConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.jprotractor; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.Properties; | ||
|
||
public class JProtractorConfiguration { | ||
private static final String PAGE_LOAD_TIMEOUT = "PAGE_LOAD_TIMEOUT"; | ||
private static final String WEBDRIVER_TIMEOUT = "WEBDRIVER_TIMEOUT"; | ||
private static final String ANGULAR_TIMEOUT = "ANGULAR_TIMEOUT"; | ||
private static final String PAGE_SYNC_TIMEOUT = "PAGE_SYNC_TIMEOUT"; | ||
public static final long DEFAULT_PAGE_LOAD_TIMEOUT = 10 * 1000; | ||
public static final long DEFAULT_PAGE_SYNC_TIMEOUT = 11 * 1000; | ||
public static final long DEFAULT_ANGULAR_TIMEOUT = 10 * 1000; | ||
public static final long DEFAULT_WEBDRIVER_TIMEOUT = 11 * 1000; | ||
private static Properties properties; | ||
|
||
public static long getPageLoadTimeout() { | ||
return getProperty(PAGE_LOAD_TIMEOUT); | ||
} | ||
|
||
public static long getPageSyncTimeout() { | ||
return getProperty(PAGE_SYNC_TIMEOUT); | ||
} | ||
|
||
public static long getAngularTimeout() { | ||
return getProperty(ANGULAR_TIMEOUT); | ||
} | ||
|
||
public static long getWebDriverTimeout() { | ||
return getProperty(WEBDRIVER_TIMEOUT); | ||
} | ||
|
||
private static long getProperty(String key) { | ||
if (properties == null) | ||
loadDefaultProperties(); | ||
return Long.parseLong((String) properties.get(key)); | ||
} | ||
|
||
private static void loadDefaultProperties() { | ||
properties = new Properties(); | ||
setProperty(PAGE_LOAD_TIMEOUT, DEFAULT_PAGE_LOAD_TIMEOUT); | ||
setProperty(PAGE_SYNC_TIMEOUT, DEFAULT_PAGE_SYNC_TIMEOUT); | ||
setProperty(ANGULAR_TIMEOUT, DEFAULT_ANGULAR_TIMEOUT); | ||
setProperty(WEBDRIVER_TIMEOUT, DEFAULT_WEBDRIVER_TIMEOUT); | ||
} | ||
|
||
private static void setProperty(String key, long value) { | ||
properties.setProperty(key, "" + value); | ||
} | ||
|
||
public static void loadConfig(URL url) throws IOException { | ||
loadDefaultProperties(); | ||
if (url != null) | ||
properties.load(url.openStream()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/jprotractor/JProtractorConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.jprotractor; | ||
|
||
import static com.jprotractor.JProtractorConfiguration.getAngularTimeout; | ||
import static com.jprotractor.JProtractorConfiguration.getPageLoadTimeout; | ||
import static com.jprotractor.JProtractorConfiguration.getWebDriverTimeout; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.openqa.selenium.WebDriver; | ||
|
||
public class JProtractorConfigurator { | ||
private static TimeUnit TIMEUNIT = TimeUnit.MILLISECONDS; | ||
|
||
public static WebDriver setup(WebDriver driver) { | ||
driver.manage().timeouts() | ||
.pageLoadTimeout(getPageLoadTimeout(), TIMEUNIT) | ||
.implicitlyWait(getWebDriverTimeout(), TIMEUNIT) | ||
.setScriptTimeout(getAngularTimeout(), TIMEUNIT); | ||
return driver; | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
src/test/java/com/jprotractor/CustomConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.jprotractor; | ||
|
||
import static com.jprotractor.JProtractorConfiguration.*; | ||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.junit.Assert.*; | ||
|
||
import java.net.URL; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class CustomConfigurationTest { | ||
|
||
@BeforeClass | ||
public static void setup() throws Exception { | ||
URL properties = CustomConfigurationTest.class.getClassLoader() | ||
.getResource("jprotractor.properties"); | ||
JProtractorConfiguration.loadConfig(properties); | ||
} | ||
|
||
@Test | ||
public void testPageLoadTimeout() throws Exception { | ||
assertThat(getPageLoadTimeout(), equalTo(100l)); | ||
} | ||
|
||
@Test | ||
public void testSyncPageTimeout() throws Exception { | ||
assertThat(getPageSyncTimeout(), equalTo(100l)); | ||
} | ||
|
||
@Test | ||
public void testAngularTimeout() throws Exception { | ||
assertThat(getAngularTimeout(), equalTo(100l)); | ||
} | ||
|
||
@Test | ||
public void testWebDriverTimeout() throws Exception { | ||
assertThat(getWebDriverTimeout(), equalTo(100l)); | ||
} | ||
|
||
@AfterClass | ||
public static void revert() throws Exception { | ||
JProtractorConfiguration.loadConfig(null); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/test/java/com/jprotractor/DefaultConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.jprotractor; | ||
|
||
import static com.jprotractor.JProtractorConfiguration.*; | ||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
|
||
public class DefaultConfigurationTest { | ||
|
||
@Test | ||
public void testPageLoadTimeout() throws Exception { | ||
assertThat(getPageLoadTimeout(), equalTo(DEFAULT_PAGE_LOAD_TIMEOUT)); | ||
} | ||
|
||
@Test | ||
public void testSyncPageTimeout() throws Exception { | ||
assertThat(getPageSyncTimeout(), equalTo(DEFAULT_PAGE_SYNC_TIMEOUT)); | ||
} | ||
|
||
@Test | ||
public void testAngularTimeout() throws Exception { | ||
assertThat(getAngularTimeout(), equalTo(DEFAULT_ANGULAR_TIMEOUT)); | ||
} | ||
|
||
@Test | ||
public void testWebDriverTimeout() throws Exception { | ||
assertThat(getWebDriverTimeout(), equalTo(DEFAULT_WEBDRIVER_TIMEOUT)); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/test/java/com/jprotractor/JProtractorConfiguratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.jprotractor; | ||
|
||
import static com.jprotractor.JProtractorConfiguration.*; | ||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.junit.Assert.*; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import com.jprotractor.mocks.WebDriverSpy; | ||
|
||
public class JProtractorConfiguratorTest { | ||
|
||
private static WebDriverSpy driver; | ||
|
||
@BeforeClass | ||
public static void init() throws Exception { | ||
driver = new WebDriverSpy(); | ||
JProtractorConfigurator.setup(driver); | ||
} | ||
|
||
@Test | ||
public void testPageLoadTimeout() throws Exception { | ||
assertThat(driver.getPageLoadTimeout(), | ||
equalTo(DEFAULT_PAGE_LOAD_TIMEOUT)); | ||
} | ||
|
||
@Test | ||
public void testImplicitWait() throws Exception { | ||
assertThat(driver.getImplicitTimeout(), | ||
equalTo(DEFAULT_WEBDRIVER_TIMEOUT)); | ||
} | ||
|
||
@Test | ||
public void testScriptTimeout() throws Exception { | ||
assertThat(driver.getScriptTimeout(), | ||
equalTo(DEFAULT_ANGULAR_TIMEOUT)); | ||
} | ||
} |
Oops, something went wrong.