serenity-bdd/serenity-core

4.0.0-beta JavascriptExecutor script is not executed #3231

vayaszsolt posted onGitHub

Hi,

I switched to use 4.0.0-beta2 since the 3.2.8 version's WebDriver was too old for the current Chrome version. As I understood the current version use the DriverManager provided from Selenium.

After I switched and I resolved the breaking changes I cannot use the JavascriptExecutor with the new driver.

JavascriptExecutor js = (JavascriptExecutor) driver; String sentence = "window.sessionStorage.setItem(\"" + name + "\"" + ", \"" + value + "\")"; js.executeScript(sentence);

The reason behind this is the "proxiedWebDriver" is null inside the WebDriverFacade class.

What additional configuration do I need to do in order the "proxiedWebDriver" to be initialized?


The proxiedWebDriver is instantiated the first time you interact with the page, e.g when you open a URL.

posted by wakaleo over 1 year ago

The browser is opened and the desired URL is set:

String url = serenityConfiguration.getProperty("webdriver.base.fe.auth.url");
actor.attemptsTo(PageNavigation.openBrowser(url));

After this I want to set the "token" session variable in order to skip the login page. This it worked with the previous version.

My complete code:

       //Open the application, login page
        String url = serenityConfiguration.getProperty("webdriver.base.fe.auth.url");
        actor.attemptsTo(PageNavigation.openBrowser(url));

       //Set the token
        JavascriptUtil.setBrowserSessionVariable(webDriver, SESSION_PARAM_TOKEN, actor.recall(PropertyUtil.ACTOR_TOKEN_PROPERTY_KEY));

      //reload the page with the application sub page -> login is skipped:
        actor.attemptsTo(PageNavigation.openPage(page));
posted by vayaszsolt over 1 year ago

Could be a bug. Can you dig into the code and propose a PR?

posted by wakaleo over 1 year ago

I will try. Before doing this I would like to be sure I am Injection the WebDriver in the correct way. The above code I use in a StepDefinition class and the WebDriver is injected:

    @Managed
    private WebDriver webDriver;

Do I inject the driver in the correct way inside the CucumberStepDefinition class?

posted by vayaszsolt over 1 year ago

I above code created a new driver that wasn't created before by Serenity. I remove that WebDriver injection inside the Definition class. I moved to use an internal Serenity class:

ThucydidesWebDriverSupport.getWebdriverManager().getCurrentDriver()

This fixed my issue.

posted by vayaszsolt over 1 year ago

Fund this Issue

$0.00
Funded

Pull requests