Skip to content

Commit 9f86d06

Browse files
committed
Merge branch 'marcospereira-updates/scalatest-3.1.0' into selenium-3.141/3.1.1.x
2 parents fbeb5f4 + 6468e80 commit 9f86d06

File tree

8 files changed

+135
-123
lines changed

8 files changed

+135
-123
lines changed

build.sbt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name := "selenium-2.45"
1+
name := "selenium-3.141"
22

33
organization := "org.scalatestplus"
44

@@ -23,13 +23,15 @@ developers := List(
2323
)
2424
)
2525

26+
scalaVersion := "2.13.1"
2627
crossScalaVersions := List("2.10.7", "2.11.12", "2.12.10", "2.13.1")
2728

2829
libraryDependencies ++= Seq(
2930
"org.scalatest" %% "scalatest" % "3.1.1",
30-
"org.seleniumhq.selenium" % "selenium-java" % "2.45.0",
31-
"org.eclipse.jetty" % "jetty-server" % "9.4.12.v20180830" % "test",
32-
"org.eclipse.jetty" % "jetty-webapp" % "9.4.12.v20180830" % "test"
31+
"org.seleniumhq.selenium" % "selenium-java" % "3.141.59",
32+
"org.seleniumhq.selenium" % "htmlunit-driver" % "2.39.0",
33+
"org.eclipse.jetty" % "jetty-server" % "9.4.12.v20180830" % Test,
34+
"org.eclipse.jetty" % "jetty-webapp" % "9.4.12.v20180830" % Test
3335
)
3436

3537
import scala.xml.{Node => XmlNode, NodeSeq => XmlNodeSeq, _}
@@ -64,7 +66,7 @@ OsgiKeys.exportPackage := Seq(
6466

6567
OsgiKeys.importPackage := Seq(
6668
"org.scalatest.*",
67-
"org.scalactic.*",
69+
"org.scalactic.*",
6870
"scala.*;version=\"$<range;[==,=+);$<replace;"+scalaBinaryVersion.value+";-;.>>\"",
6971
"*;resolution:=optional"
7072
)
@@ -92,3 +94,12 @@ credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
9294
pgpSecretRing := file((Path.userHome / ".gnupg" / "secring.gpg").getAbsolutePath)
9395

9496
pgpPassphrase := None
97+
98+
scalacOptions ++= Seq(
99+
"-deprecation",
100+
"-encoding", "utf-8",
101+
"-explaintypes",
102+
"-feature",
103+
"-unchecked",
104+
"-Ywarn-dead-code",
105+
) ++ (if (scalaBinaryVersion.value == "2.10") Seq.empty else Seq("-Ywarn-unused"))

src/main/scala/org/scalatestplus/selenium/ScreenshotCapturer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ private[selenium] trait ScreenshotCapturer {
2424
/**
2525
* Captures a screenshot and saves it as a file in the specified directory.
2626
*/
27-
def captureScreenshot(directory: String)
27+
def captureScreenshot(directory: String): Unit
2828
}

src/main/scala/org/scalatestplus/selenium/WebBrowser.scala

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ import org.openqa.selenium.By
2525
import org.openqa.selenium.WebElement
2626
import java.util.concurrent.TimeUnit
2727

28-
import scala.collection.mutable.Buffer
2928
import scala.collection.JavaConverters._
3029
import org.openqa.selenium.Cookie
3130
import java.util.Date
3231

3332
import org.scalatest.time.Span
34-
import org.scalatest.time.Milliseconds
3533
import org.openqa.selenium.TakesScreenshot
3634
import org.openqa.selenium.OutputType
3735
import java.io.File
@@ -43,9 +41,9 @@ import org.openqa.selenium.support.ui.Select
4341
import org.scalatest.exceptions.TestFailedException
4442
import org.scalatest.exceptions.StackDepthException
4543
import org.openqa.selenium.JavascriptExecutor
46-
import org.scalatest.time.Nanosecond
47-
import org.scalatest.Resources
4844
import org.scalactic.source
45+
import org.openqa.selenium.firefox.FirefoxOptions
46+
import java.io.Closeable
4947

5048
/**
5149
* Trait that provides a domain specific language (DSL) for writing browser-based tests using <a href="http://seleniumhq.org">Selenium</a>.
@@ -1577,7 +1575,7 @@ trait WebBrowser {
15771575
case e: org.openqa.selenium.NoSuchFrameException =>
15781576
throw new TestFailedException(
15791577
(_: StackDepthException) => Some("Frame at index '" + index + "' not found."),
1580-
None,
1578+
Option(e),
15811579
pos
15821580
)
15831581
}
@@ -1611,7 +1609,7 @@ trait WebBrowser {
16111609
case e: org.openqa.selenium.NoSuchFrameException =>
16121610
throw new TestFailedException(
16131611
(_: StackDepthException) => Some("Frame with name or ID '" + nameOrId + "' not found."),
1614-
None,
1612+
Option(e),
16151613
pos
16161614
)
16171615
}
@@ -1636,7 +1634,7 @@ trait WebBrowser {
16361634
case e: org.openqa.selenium.NoSuchFrameException =>
16371635
throw new TestFailedException(
16381636
(_: StackDepthException) => Some("Frame element '" + webElement + "' not found."),
1639-
None,
1637+
Option(e),
16401638
pos
16411639
)
16421640
}
@@ -1661,7 +1659,7 @@ trait WebBrowser {
16611659
case e: org.openqa.selenium.NoSuchFrameException =>
16621660
throw new TestFailedException(
16631661
(_: StackDepthException) => Some("Frame element '" + element + "' not found."),
1664-
None,
1662+
Option(e),
16651663
pos
16661664
)
16671665
}
@@ -1695,7 +1693,7 @@ trait WebBrowser {
16951693
case e: org.openqa.selenium.NoSuchWindowException =>
16961694
throw new TestFailedException(
16971695
(_: StackDepthException) => Some("Window with nameOrHandle '" + nameOrHandle + "' not found."),
1698-
None,
1696+
Option(e),
16991697
pos
17001698
)
17011699
}
@@ -2849,7 +2847,7 @@ trait WebBrowser {
28492847
Some(createTypedElement(driver.findElement(by), pos))
28502848
}
28512849
catch {
2852-
case e: org.openqa.selenium.NoSuchElementException => None
2850+
case _: org.openqa.selenium.NoSuchElementException => None
28532851
}
28542852

28552853
/**
@@ -4299,6 +4297,22 @@ trait WebBrowser {
42994297
* </pre>
43004298
*/
43014299
object capture {
4300+
4301+
private def copy(source: File, destination: File): Unit = {
4302+
4303+
def close(closeable: Closeable): Unit = if (closeable != null) closeable.close()
4304+
4305+
var outStream: FileOutputStream = null
4306+
var inputStream: FileInputStream = null
4307+
try {
4308+
inputStream = new FileInputStream(source)
4309+
outStream = new FileOutputStream(destination)
4310+
outStream.getChannel().transferFrom(inputStream.getChannel(), 0, Long.MaxValue)
4311+
} finally {
4312+
close(inputStream)
4313+
close(outStream)
4314+
}
4315+
}
43024316

43034317
/**
43044318
* Capture screenshot and save it as the specified name (if file name does not end with .png, it will be extended automatically) in capture directory,
@@ -4311,8 +4325,7 @@ trait WebBrowser {
43114325
case takesScreenshot: TakesScreenshot =>
43124326
val tmpFile = takesScreenshot.getScreenshotAs(OutputType.FILE)
43134327
val outFile = new File(targetDir, if (fileName.toLowerCase.endsWith(".png")) fileName else fileName + ".png")
4314-
new FileOutputStream(outFile).getChannel.transferFrom(
4315-
new FileInputStream(tmpFile).getChannel, 0, Long.MaxValue)
4328+
copy(tmpFile, outFile)
43164329
case _ =>
43174330
throw new UnsupportedOperationException("Screen capture is not support by " + driver.getClass.getName)
43184331
}
@@ -4328,11 +4341,9 @@ trait WebBrowser {
43284341
case takesScreenshot: TakesScreenshot =>
43294342
val tmpFile = takesScreenshot.getScreenshotAs(OutputType.FILE)
43304343
val dir = new File(dirName)
4331-
if (!dir.exists)
4332-
dir.mkdirs()
4344+
if (!dir.exists) dir.mkdirs()
43334345
val outFile = new File(dir, if (tmpFile.getName.toLowerCase.endsWith(".png")) "ScalaTest-" + tmpFile.getName else "ScalaTest-" + tmpFile.getName + ".png")
4334-
new FileOutputStream(outFile).getChannel.transferFrom(
4335-
new FileInputStream(tmpFile).getChannel, 0, Long.MaxValue)
4346+
copy(tmpFile, outFile)
43364347
case _ =>
43374348
throw new UnsupportedOperationException("Screen capture is not support by " + driver.getClass.getName)
43384349
}
@@ -4348,8 +4359,7 @@ trait WebBrowser {
43484359
val tmpFile = takesScreenshot.getScreenshotAs(OutputType.FILE)
43494360
val fileName = tmpFile.getName
43504361
val outFile = new File(targetDir, if (fileName.toLowerCase.endsWith(".png")) fileName else fileName + ".png")
4351-
new FileOutputStream(outFile).getChannel.transferFrom(
4352-
new FileInputStream(tmpFile).getChannel, 0, Long.MaxValue)
4362+
copy(tmpFile, outFile)
43534363
outFile
43544364
case _ =>
43554365
throw new UnsupportedOperationException("Screen capture is not support by " + driver.getClass.getName)
@@ -4630,15 +4640,26 @@ object HtmlUnit extends HtmlUnit
46304640
trait Firefox extends WebBrowser with Driver with ScreenshotCapturer {
46314641

46324642
/**
4633-
* The <code>FirefoxProfile</code> passed to the constructor of the <code>FirefoxDriver</code> returned by <code>webDriver</code>.
4643+
* The <code>FirefoxProfile</code> seet into <code>FirefoxOptions</code> returned by <code>firefoxOptions</code>.
46344644
*
46354645
* <p>
4636-
* The <code>FirefoxDriver</code> uses the <code>FirefoxProfile</code> defined as <code>firefoxProfile</code>. By default this is just a <code>new FirefoxProfile</code>.
4646+
* The <code>FirefoxOptions</code> uses the <code>FirefoxProfile</code> defined as <code>firefoxProfile</code>. By default this is just a <code>new FirefoxProfile</code>.
46374647
* You can mutate this object to modify the profile, or override <code>firefoxProfile</code>.
46384648
* </p>
46394649
*/
4650+
@deprecated("Use firefoxOptions instead", "3.1.0")
46404651
val firefoxProfile = new FirefoxProfile()
46414652

4653+
/**
4654+
* The <code>FirefoxOptions</code> passed to the constructor of the <code>FirefoxDriver</code> returned by <code>webDriver</code>.
4655+
*
4656+
* <p>
4657+
* The <code>FirefoxDriver</code> uses the <code>FirefoxOptions</code> defined as <code>firefoxOptions</code>. By default this is just a <code>new FirefoxOptions</code>.
4658+
* You can mutate this object to modify the profile, or override <code>firefoxProfile</code>.
4659+
* </p>
4660+
*/
4661+
val firefoxOptions = new FirefoxOptions().setProfile(firefoxProfile)
4662+
46424663
/**
46434664
* <code>WebBrowser</code> subtrait that defines an implicit <code>WebDriver</code> for Firefox (an <code>org.openqa.selenium.firefox.FirefoxDriver</code>), with a default
46444665
* Firefox profile.
@@ -4648,7 +4669,7 @@ trait Firefox extends WebBrowser with Driver with ScreenshotCapturer {
46484669
* You can mutate this object to modify the profile, or override <code>firefoxProfile</code>.
46494670
* </p>
46504671
*/
4651-
implicit val webDriver: WebDriver = new FirefoxDriver(firefoxProfile)
4672+
implicit val webDriver: WebDriver = new FirefoxDriver(firefoxOptions)
46524673

46534674
/**
46544675
* Captures a screenshot and saves it as a file in the specified directory.

src/test/scala/org/scalatestplus/selenium/DriverSpec.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package org.scalatestplus.selenium
22

33
import org.scalatest._
44
import SharedHelpers.EventRecordingReporter
5-
import org.openqa.selenium.firefox.{FirefoxDriver, FirefoxProfile}
5+
import org.openqa.selenium.firefox.{FirefoxDriver, FirefoxOptions}
66
import org.openqa.selenium.safari.SafariDriver
77
import org.openqa.selenium.chrome.ChromeDriver
88
import org.openqa.selenium.ie.InternetExplorerDriver
@@ -34,8 +34,6 @@ class DriverSpec extends funspec.AnyFunSpec {
3434
}
3535

3636
class GoogleSearchSpecWithChrome extends GoogleSearchSpec with Chrome
37-
class GoogleSearchSpecWithSafari extends GoogleSearchSpec with Safari
38-
class GoogleSearchSpecWithInternetExplorer extends GoogleSearchSpec with InternetExplorer
3937
class GoogleSearchSpecWithFirefox extends GoogleSearchSpec with Firefox
4038

4139
it("should work with Chrome", Slow) {
@@ -60,7 +58,7 @@ class DriverSpec extends funspec.AnyFunSpec {
6058

6159
it("should work with Firefox", Slow) {
6260
// Cancel when Firefox is not available
63-
try new FirefoxDriver(new FirefoxProfile) catch { case e: Throwable => cancel(e) }
61+
try new FirefoxDriver(new FirefoxOptions) catch { case e: Throwable => cancel(e) }
6462
val s = new GoogleSearchSpecWithFirefox
6563
val rep = new EventRecordingReporter
6664
s.run(None, Args(reporter = rep))

src/test/scala/org/scalatestplus/selenium/ScreenshotSpec.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ package org.scalatestplus.selenium
1717

1818
import org.scalatest._
1919
import org.scalatest.time.SpanSugar
20-
import java.io.File
21-
import org.scalatest.Args
22-
import org.scalatestplus.selenium.SharedHelpers.SilentReporter
2320
import org.scalatest.Ignore
2421
import org.scalatest.matchers.should.Matchers
2522

0 commit comments

Comments
 (0)