-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
execute navigateTo automatically for every test #11 -
simplified implementation and providing more control on navigateTo execution
- Loading branch information
Daniel.Rey
committed
Oct 24, 2016
1 parent
3c2c483
commit 363a618
Showing
8 changed files
with
125 additions
and
69 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
83 changes: 83 additions & 0 deletions
83
core/src/main/scala/org/scalawebtest/core/BaseConfiguration.scala
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,83 @@ | ||
package org.scalawebtest.core | ||
|
||
class BaseConfiguration() { | ||
var configurations: Map[String, WebClientExposingDriver => Unit] = Map() | ||
|
||
//initialize with sensible default configuration | ||
disableJavaScript() | ||
swallowJavaScriptErrors() | ||
disableCss() | ||
|
||
/** | ||
* Enable JavaScript evaluation in the webDriver | ||
* and choose whether to throw on JavaScript error | ||
*/ | ||
def enableJavaScript(throwOnError: Boolean): Unit = { | ||
configurations += "enableJavaScript" -> | ||
((webDriver: WebClientExposingDriver) => webDriver.getOptions.setJavaScriptEnabled(true)) | ||
configurations += "throwOnJSError" -> | ||
((webDriver: WebClientExposingDriver) => webDriver.getOptions.setThrowExceptionOnFailingStatusCode(throwOnError)) | ||
} | ||
|
||
/** | ||
* Disable JavaScript evaluation as well as throwing on JavaScript error in the webDriver | ||
*/ | ||
def disableJavaScript(): Unit = { | ||
configurations += "enableJavaScript" -> ((webDriver: WebClientExposingDriver) => webDriver.getOptions.setJavaScriptEnabled(false)) | ||
configurations += "throwOnJSError" -> ((webDriver: WebClientExposingDriver) => webDriver.getOptions.setThrowExceptionOnFailingStatusCode(false)) | ||
} | ||
|
||
/** | ||
* Throw on JavaScript Error. Preferably use [[BaseConfiguration.disableJavaScript()]], as the two configurations only make sense when combined. | ||
*/ | ||
def throwOnJavaScriptError(): Unit = configurations += "throwOnJSError" -> | ||
((webDriver: WebClientExposingDriver) => webDriver.getOptions.setThrowExceptionOnFailingStatusCode(true)) | ||
|
||
/** | ||
* Silently swallow JavaScript errors. Preferably use [[BaseConfiguration.disableJavaScript()]], as the two configurations only make sense when combined. | ||
*/ | ||
def swallowJavaScriptErrors(): Unit = configurations += "throwOnJSError" -> | ||
((webDriver: WebClientExposingDriver) => webDriver.getOptions.setThrowExceptionOnFailingStatusCode(false)) | ||
|
||
/** | ||
* Enable CSS evaluation in the webDriver. | ||
*/ | ||
def enableCss(): Unit = configurations += "enableCss" -> | ||
((webDriver: WebClientExposingDriver) => webDriver.getOptions.setCssEnabled(true)) | ||
|
||
/** | ||
* Disable CSS evaluation in the webDriver. | ||
*/ | ||
def disableCss(): Unit = configurations += "enableCss" -> | ||
((webDriver: WebClientExposingDriver) => webDriver.getOptions.setCssEnabled(false)) | ||
|
||
} | ||
|
||
class LoginConfiguration extends BaseConfiguration | ||
class Configuration extends BaseConfiguration { | ||
//initialize with sensible default configuration | ||
var navigateToEnabled = true | ||
var navigateToEnforced = false | ||
|
||
/** | ||
* Enabling navigateTo is the default. [[org.scalatest.BeforeAndAfterEach.beforeEach]] Test navigateTo is called with the current value of [[IntegrationSpec.path]] | ||
*/ | ||
def enableNavigateTo(): Unit = navigateToEnabled = true | ||
|
||
/** | ||
* Disables the navigateTo call, which otherwise happens in [[org.scalatest.BeforeAndAfterEach.beforeEach]] | ||
*/ | ||
def disableNavigateTo(): Unit = navigateToEnabled = false | ||
|
||
/** | ||
* By default navigateTo only navigates to the configured path, if it isn't the same as the currentPage. | ||
* By enabling enforceNavigateTo, [[org.scalatest.selenium.WebBrowser.goTo()]] is always called. | ||
*/ | ||
def enforceNavigateTo(): Unit = navigateToEnforced = true | ||
|
||
/** | ||
* This is the default behavior. NavigateTo only calls [[org.scalatest.selenium.WebBrowser.goTo()]], if the | ||
* currentPage isn't the same as the configured path. | ||
*/ | ||
def doNotEnforceNavigateTo(): Unit = navigateToEnforced = false | ||
} |
35 changes: 0 additions & 35 deletions
35
core/src/main/scala/org/scalawebtest/core/Configuration.scala
This file was deleted.
Oops, something went wrong.
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
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
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
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
12 changes: 12 additions & 0 deletions
12
...gration_test/src/it/scala/org/scalawebtest/integration/navigation/DisableNavigateTo.scala
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,12 @@ | ||
package org.scalawebtest.integration.navigation | ||
|
||
import org.scalawebtest.core.IntegrationFlatSpec | ||
|
||
class DisableNavigateTo extends IntegrationFlatSpec{ | ||
path = "/a.jsp" | ||
config.disableNavigateTo() | ||
|
||
"When navigateTo is disabled" should "remain on about:blank" in { | ||
webDriver.getCurrentUrl shouldEqual "about:blank" | ||
} | ||
} |