-
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.
Make ScalaWebTest compatible with all implementations of Selenium Web…
…Driver #74 - correctly handle JSON responses in Chrome (stripping the HTML wrapper) - added basic tests, to verify functionality across all browsers - moved comments from HtmlUnitConfiguration to BaseConfiguration - with this commit the change should be good enough to be merged back to develop
- Loading branch information
Showing
9 changed files
with
165 additions
and
21 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
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
...awebtest-integration/src/it/scala/org/scalawebtest/integration/browser/HtmlUnitSpec.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.browser | ||
|
||
import org.scalawebtest.integration.ScalaWebTestBaseSpec | ||
import org.scalawebtest.integration.browser.behaviors.BrowserBehaviors | ||
|
||
class HtmlUnitSpec extends ScalaWebTestBaseSpec with BrowserBehaviors { | ||
path = "/" | ||
|
||
"HtmlUnit" should behave like aWebBrowserWithElementLookup | ||
it should behave like anHtmlGauge | ||
it should behave like aJsonGauge | ||
} |
13 changes: 13 additions & 0 deletions
13
...st-integration/src/it/scala/org/scalawebtest/integration/browser/SeleniumChromeSpec.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,13 @@ | ||
package org.scalawebtest.integration.browser | ||
|
||
import org.scalawebtest.core.browser.SeleniumChrome | ||
import org.scalawebtest.integration.ScalaWebTestBaseSpec | ||
import org.scalawebtest.integration.browser.behaviors.BrowserBehaviors | ||
|
||
class SeleniumChromeSpec extends ScalaWebTestBaseSpec with SeleniumChrome with BrowserBehaviors { | ||
path = "/" | ||
|
||
"SeleniumChrome" should behave like aWebBrowserWithElementLookup() | ||
it should behave like anHtmlGauge | ||
it should behave like aJsonGauge | ||
} |
7 changes: 7 additions & 0 deletions
7
...ration/src/it/scala/org/scalawebtest/integration/browser/behaviors/BrowserBehaviors.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,7 @@ | ||
package org.scalawebtest.integration.browser.behaviors | ||
|
||
import org.scalawebtest.integration.ScalaWebTestBaseSpec | ||
|
||
trait BrowserBehaviors extends WebBrowserBehavior with HtmlGaugeBehavior with JsonGaugeBehavior { | ||
self: ScalaWebTestBaseSpec => | ||
} |
40 changes: 40 additions & 0 deletions
40
...ation/src/it/scala/org/scalawebtest/integration/browser/behaviors/HtmlGaugeBehavior.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,40 @@ | ||
package org.scalawebtest.integration.browser.behaviors | ||
|
||
import org.scalawebtest.integration.ScalaWebTestBaseSpec | ||
|
||
trait HtmlGaugeBehavior { | ||
self: ScalaWebTestBaseSpec => | ||
|
||
def anHtmlGauge(): Unit = { | ||
it should "be capable to fit a simple HTML Gauge" in { | ||
navigateTo("/elementsList.jsp") | ||
fits( | ||
<ul> | ||
<li><div>Link 2</div></li> | ||
</ul>) | ||
} | ||
it should "be capable to fit an HTML Gauge containing a list of items" in { | ||
fits( | ||
<ul> | ||
<li><div>Link 1</div></li> | ||
<li><div>Link 2</div></li> | ||
<li><div>Link 3</div></li> | ||
</ul>) | ||
} | ||
it should "be capable to not fit an HTML Gauge, if the element is missing" in { | ||
doesnt fit | ||
<ul> | ||
<li> | ||
<p>Link1</p> | ||
</li> | ||
</ul> | ||
} | ||
it should "be capable to not fit an HTML Gauge, if the element order is wrong" in { | ||
doesnt fit | ||
<ul> | ||
<li><div>Link 3</div></li> | ||
<li><div>Link 1</div></li> | ||
</ul> | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...ation/src/it/scala/org/scalawebtest/integration/browser/behaviors/JsonGaugeBehavior.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,54 @@ | ||
package org.scalawebtest.integration.browser.behaviors | ||
|
||
import org.scalawebtest.integration.ScalaWebTestBaseSpec | ||
|
||
trait JsonGaugeBehavior { | ||
|
||
self: ScalaWebTestBaseSpec => | ||
|
||
//TODO: replace String comparison with JsonGauge, after Scala 2.10 support was removed from ScalaWebTest | ||
def aJsonGauge(): Unit = { | ||
def removeWhitespaces(s: String): String = { | ||
s.replaceAll("\\s", "") | ||
} | ||
|
||
it should "be capable to handle JSON responses (some browsers wrap this in HTML and need special treatment)" in { | ||
navigateTo("/jsonResponse.json.jsp") | ||
removeWhitespaces(webDriver.getPageSource) shouldBe | ||
removeWhitespaces(""" | ||
|{ | ||
| "name": "Dijkstra", | ||
| "firstName": "Edsger", | ||
| "yearOfBirth": 1930, | ||
| "theories": [ | ||
| "shortest path", | ||
| "graph theory" | ||
| ], | ||
| "isTuringAwardWinner": true, | ||
| "universities": [ | ||
| { | ||
| "name": "Universität Leiden", | ||
| "begin": 1948, | ||
| "end": 1956 | ||
| }, | ||
| { | ||
| "name": "Mathematisch Centrum Amsterdam", | ||
| "begin": 1951, | ||
| "end": 1959 | ||
| }, | ||
| { | ||
| "name": "Technische Universiteit Eindhoven", | ||
| "begin": 1962, | ||
| "end": 1984 | ||
| }, | ||
| { | ||
| "name": "University of Texas at Austin", | ||
| "begin": 1984, | ||
| "end": 1999 | ||
| } | ||
| ], | ||
| "falseTheories": null | ||
|}""".stripMargin) | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...tion/src/it/scala/org/scalawebtest/integration/browser/behaviors/WebBrowserBehavior.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,18 @@ | ||
package org.scalawebtest.integration.browser.behaviors | ||
|
||
import org.scalatest.OptionValues | ||
import org.scalawebtest.integration.ScalaWebTestBaseSpec | ||
|
||
trait WebBrowserBehavior extends OptionValues { | ||
self: ScalaWebTestBaseSpec => | ||
def aWebBrowserWithElementLookup(): Unit = { | ||
it should "be capable to find a single element in an HTML document" in { | ||
navigateTo("/") | ||
find(cssSelector("h1")).value.text shouldBe "ScalaWebTest - Mock Server" | ||
} | ||
it should "be capable to find a list of elements in an HTML document" in { | ||
navigateTo("/elementsList.jsp") | ||
findAll(cssSelector("li")) should have size 3 | ||
} | ||
} | ||
} |