@@ -25,13 +25,11 @@ import org.openqa.selenium.By
25
25
import org .openqa .selenium .WebElement
26
26
import java .util .concurrent .TimeUnit
27
27
28
- import scala .collection .mutable .Buffer
29
28
import scala .collection .JavaConverters ._
30
29
import org .openqa .selenium .Cookie
31
30
import java .util .Date
32
31
33
32
import org .scalatest .time .Span
34
- import org .scalatest .time .Milliseconds
35
33
import org .openqa .selenium .TakesScreenshot
36
34
import org .openqa .selenium .OutputType
37
35
import java .io .File
@@ -43,9 +41,9 @@ import org.openqa.selenium.support.ui.Select
43
41
import org .scalatest .exceptions .TestFailedException
44
42
import org .scalatest .exceptions .StackDepthException
45
43
import org .openqa .selenium .JavascriptExecutor
46
- import org .scalatest .time .Nanosecond
47
- import org .scalatest .Resources
48
44
import org .scalactic .source
45
+ import org .openqa .selenium .firefox .FirefoxOptions
46
+ import java .io .Closeable
49
47
50
48
/**
51
49
* 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 {
1577
1575
case e : org.openqa.selenium.NoSuchFrameException =>
1578
1576
throw new TestFailedException (
1579
1577
(_ : StackDepthException ) => Some (" Frame at index '" + index + " ' not found." ),
1580
- None ,
1578
+ Option (e) ,
1581
1579
pos
1582
1580
)
1583
1581
}
@@ -1611,7 +1609,7 @@ trait WebBrowser {
1611
1609
case e : org.openqa.selenium.NoSuchFrameException =>
1612
1610
throw new TestFailedException (
1613
1611
(_ : StackDepthException ) => Some (" Frame with name or ID '" + nameOrId + " ' not found." ),
1614
- None ,
1612
+ Option (e) ,
1615
1613
pos
1616
1614
)
1617
1615
}
@@ -1636,7 +1634,7 @@ trait WebBrowser {
1636
1634
case e : org.openqa.selenium.NoSuchFrameException =>
1637
1635
throw new TestFailedException (
1638
1636
(_ : StackDepthException ) => Some (" Frame element '" + webElement + " ' not found." ),
1639
- None ,
1637
+ Option (e) ,
1640
1638
pos
1641
1639
)
1642
1640
}
@@ -1661,7 +1659,7 @@ trait WebBrowser {
1661
1659
case e : org.openqa.selenium.NoSuchFrameException =>
1662
1660
throw new TestFailedException (
1663
1661
(_ : StackDepthException ) => Some (" Frame element '" + element + " ' not found." ),
1664
- None ,
1662
+ Option (e) ,
1665
1663
pos
1666
1664
)
1667
1665
}
@@ -1695,7 +1693,7 @@ trait WebBrowser {
1695
1693
case e : org.openqa.selenium.NoSuchWindowException =>
1696
1694
throw new TestFailedException (
1697
1695
(_ : StackDepthException ) => Some (" Window with nameOrHandle '" + nameOrHandle + " ' not found." ),
1698
- None ,
1696
+ Option (e) ,
1699
1697
pos
1700
1698
)
1701
1699
}
@@ -2849,7 +2847,7 @@ trait WebBrowser {
2849
2847
Some (createTypedElement(driver.findElement(by), pos))
2850
2848
}
2851
2849
catch {
2852
- case e : org.openqa.selenium.NoSuchElementException => None
2850
+ case _ : org.openqa.selenium.NoSuchElementException => None
2853
2851
}
2854
2852
2855
2853
/**
@@ -4299,6 +4297,22 @@ trait WebBrowser {
4299
4297
* </pre>
4300
4298
*/
4301
4299
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
+ }
4302
4316
4303
4317
/**
4304
4318
* 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 {
4311
4325
case takesScreenshot : TakesScreenshot =>
4312
4326
val tmpFile = takesScreenshot.getScreenshotAs(OutputType .FILE )
4313
4327
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)
4316
4329
case _ =>
4317
4330
throw new UnsupportedOperationException (" Screen capture is not support by " + driver.getClass.getName)
4318
4331
}
@@ -4328,11 +4341,9 @@ trait WebBrowser {
4328
4341
case takesScreenshot : TakesScreenshot =>
4329
4342
val tmpFile = takesScreenshot.getScreenshotAs(OutputType .FILE )
4330
4343
val dir = new File (dirName)
4331
- if (! dir.exists)
4332
- dir.mkdirs()
4344
+ if (! dir.exists) dir.mkdirs()
4333
4345
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)
4336
4347
case _ =>
4337
4348
throw new UnsupportedOperationException (" Screen capture is not support by " + driver.getClass.getName)
4338
4349
}
@@ -4348,8 +4359,7 @@ trait WebBrowser {
4348
4359
val tmpFile = takesScreenshot.getScreenshotAs(OutputType .FILE )
4349
4360
val fileName = tmpFile.getName
4350
4361
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)
4353
4363
outFile
4354
4364
case _ =>
4355
4365
throw new UnsupportedOperationException (" Screen capture is not support by " + driver.getClass.getName)
@@ -4630,15 +4640,26 @@ object HtmlUnit extends HtmlUnit
4630
4640
trait Firefox extends WebBrowser with Driver with ScreenshotCapturer {
4631
4641
4632
4642
/**
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>.
4634
4644
*
4635
4645
* <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>.
4637
4647
* You can mutate this object to modify the profile, or override <code>firefoxProfile</code>.
4638
4648
* </p>
4639
4649
*/
4650
+ @ deprecated(" Use firefoxOptions instead" , " 3.1.0" )
4640
4651
val firefoxProfile = new FirefoxProfile ()
4641
4652
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
+
4642
4663
/**
4643
4664
* <code>WebBrowser</code> subtrait that defines an implicit <code>WebDriver</code> for Firefox (an <code>org.openqa.selenium.firefox.FirefoxDriver</code>), with a default
4644
4665
* Firefox profile.
@@ -4648,7 +4669,7 @@ trait Firefox extends WebBrowser with Driver with ScreenshotCapturer {
4648
4669
* You can mutate this object to modify the profile, or override <code>firefoxProfile</code>.
4649
4670
* </p>
4650
4671
*/
4651
- implicit val webDriver : WebDriver = new FirefoxDriver (firefoxProfile )
4672
+ implicit val webDriver : WebDriver = new FirefoxDriver (firefoxOptions )
4652
4673
4653
4674
/**
4654
4675
* Captures a screenshot and saves it as a file in the specified directory.
0 commit comments