Chetan
Chetan

Reputation: 302

how to pass implicit val to base call in scala

I am new to Scala and still learning. And I am trying to perform/design following approach:

class BasePage (implicit val webDriver: WebDriver, val environment: String) {...}

class LoginPage extends BasePage {...}

class testSpecs extends Specification{
    new WithBrowser(webDriver = currentDriver, app = application){

    implicit val webDriver= browser.webDriver
    implicit val environment = s"localhost:$port"

    val loginPage = new LoginPage()
    ...
}

What I want is to make webDriver and environment available (when first time it is created) to all the page object classes throughout the test script/test in testSpecs.

In this approach I am getting error like :

could not find implicit value for parameter webDriver: org.openqa.selenium.WebDriver

  1. How can we fix this problem?
  2. What are the other better approach i can use?

Thanks very much in advance.

Upvotes: 1

Views: 131

Answers (1)

Jasper-M
Jasper-M

Reputation: 15086

The constructor to BasePage expects 2 arguments. When class LoginPage is defined, those implicit values aren't in scope, so you'll have to write it like this:

class LoginPage(implicit val webDriver: WebDriver, val environment: String) extends BasePage {...}

Now LoginPage also has 2 implicit parameters which are passed implicitly to BasePage's constructor.

Upvotes: 1

Related Questions