2

I have a few scala tests up and running but am confused as to how to close/quit webdriver upon completion of the run. I am aware of beforeAndAfterAll, but it seems that it acts on each test class whereas I only want to quit webdriver at the end (not inbetween each test & then restarting it). It doesn't appear to be doing anything, but here's what I've currently got:

class testRunHandler extends org.scalatest.Reporter{
    import org.scalatest.events._
    def apply(event: Event){
      event match{
        case _:RunCompleted => foo.driver.close()
        case _ =>
      }
    }

I tried to follow this but wasn't sure how to apply it: Doing something before or after all Scalatest tests

bad_coder
  • 11,289
  • 20
  • 44
  • 72
G M
  • 21
  • 3

1 Answers1

1

You can use this:

sys.addShutdownHook { foo.driver.close() }

It's probably best if you make sure this line is only executed once. I've put in an object, near where I configure the driver.

jqno
  • 15,133
  • 7
  • 57
  • 84