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

Logging doesn't pick up JavascriptExecutor command. #2492

Closed
sebastiangrigore opened this issue Jun 22, 2021 · 3 comments
Closed

Logging doesn't pick up JavascriptExecutor command. #2492

sebastiangrigore opened this issue Jun 22, 2021 · 3 comments

Comments

@sebastiangrigore
Copy link

sebastiangrigore commented Jun 22, 2021

Hello,
I'm trying to pick up the number of DataLayer elements from a page and then loop through them and check their contents.
Using Serenity 2.3.6 with Java. My code:

  `JavascriptExecutor js = (JavascriptExecutor) getDriver();
    js.executeScript("console.clear()");
    js.executeScript("console.log(window.dataLayer.length)");

    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
    desiredCapabilities.setCapability("goog:loggingPrefs", logPrefs);
    LogEntries log = getDriver().manage().logs().get(LogType.BROWSER);

    String consoleLog = log.getAll().toString();
    String temp = consoleLog.substring(consoleLog.length() - 3);
    String end = temp.substring(0, temp.length() - 1);
    int dataLayerEntries = Integer.parseInt(end);'

 
    The problem is that the logging doesn't pick up the js.executeScript stuff and still returns the console log before the clearing. I've tried adding to serenity.conf and serenity.properties the following 2 pieces of code respectively:


    `webdriver {
logprefs {
    driver = ALL
    browser = ALL
}

}'

chrome.switches=--enable-logging,--v=2,--no-sandbox,--log-level=0 chrome.capabilities.loggingPrefs={"driver":"ALL","browser":"ALL"}

Any ideas, suggestions?

@wakaleo
Copy link
Member

wakaleo commented Jun 22, 2021

Are you expecting Serenity or Selenium to perform this logging?

@sebastiangrigore
Copy link
Author

sebastiangrigore commented Jun 22, 2021

Are you expecting Serenity or Selenium to perform this logging?

Selenium but I'm forced by BrowserStack integration to use the getDriver() method, instead of creating my own custom driver.
I've used the code below and it works correctly:

'ChromeOptions options = new ChromeOptions();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
options.setCapability("goog:loggingPrefs", logPrefs);
WebDriver driver = new ChromeDriver(options);'

@wakaleo
Copy link
Member

wakaleo commented Jul 4, 2021

Have a look at the AddLoggingPreferences class and see what it is doing differently to the code you would expect.

@wakaleo wakaleo closed this as completed Feb 12, 2022
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