Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running tests tagged with one browser still opens other browser windows #14

Open
oscarvarto opened this issue Jul 31, 2020 · 2 comments

Comments

@oscarvarto
Copy link

oscarvarto commented Jul 31, 2020

A minimal project showing the problem is here:

https://github.com/oscarvarto/CrossBrowserTesting

Running

$ sbt
sbt:CrossBrowserTesting> test

runs the WikipediaSpec on Chrome, Firefox and Safari, as expected. But, if I try to run only the Chrome test with

sbt:CrossBrowserTesting> testOnly * -- -n org.scalatest.tags.ChromeBrowser

the Firefox and Safari browsers are still started (even though none of the test are executed for these)
and the windows are not closed.

What needs to be done in order to run only the tests tagged with a single browser, and not create other browser windows?

@oscarvarto oscarvarto changed the title Running tests tagged with one browser still opens other existing browser windows Running tests tagged with one browser still opens other browser windows Jul 31, 2020
@cheeseng
Copy link
Contributor

@oscarvarto Thanks for minimal project, I'll take a look and see if there's anything we can improve.

@cheeseng
Copy link
Contributor

@oscarvarto Yes I think we'll have to change the webDriver field to def in Driver and make its subclasses (Firefox, Chrome etc.) to use lazy val for this. But unfortunately, this will be a change that will break binary compatibility so I think we can't do it in 3.2.2.x (unless @bvenners is ok with it), may be we can do it in 3.3.0.0 (planned for ScalaTest 3.3.0).

For quick workaround, Driver and its subclasses are quite simple and can be duplicated easily in your own code, e.g.:

trait MyDriver { this: WebBrowser =>
  implicit def webDriver: WebDriver
}

trait MyHtmlUnit extends WebBrowser with MyDriver {
  implicit lazy val webDriver: HtmlUnitDriver = new HtmlUnitDriver(true)
}

object MyHtmlUnit extends MyHtmlUnit
...

Fyi source code of Driver and its subclasses is here:

https://github.com/scalatest/scalatestplus-selenium/blob/selenium-3.141/3.2.1.x/src/main/scala/org/scalatestplus/selenium/WebBrowser.scala#L4576-L4759

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants