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

4.0.0-beta JavascriptExecutor script is not executed #3231

Closed
vayaszsolt opened this issue Aug 18, 2023 · 5 comments
Closed

4.0.0-beta JavascriptExecutor script is not executed #3231

vayaszsolt opened this issue Aug 18, 2023 · 5 comments

Comments

@vayaszsolt
Copy link

vayaszsolt commented Aug 18, 2023

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?

@wakaleo
Copy link
Member

wakaleo commented Aug 18, 2023

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

@vayaszsolt
Copy link
Author

vayaszsolt commented Aug 18, 2023

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));

@wakaleo
Copy link
Member

wakaleo commented Aug 18, 2023

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

@vayaszsolt
Copy link
Author

vayaszsolt commented Aug 18, 2023

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?

@vayaszsolt
Copy link
Author

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.

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