wttech / bobcat

Bobcat is an automated testing framework for functional testing of web applications.
https://cognifide.github.io/bobcat/
Apache License 2.0
90 stars 40 forks source link

Chrome Headless Mode #188

Closed subiron closed 4 years ago

subiron commented 7 years ago

Starting from version 59 chrome supports headless mode (on linux and MacOs) this may improve the performance of tests.

Please check if all existing features still works in this mode and measure performance differences.

Also please provide docs how to execute tests in headless mode for chrome.

see https://developers.google.com/web/updates/2017/04/headless-chrome

Shaihuludus commented 7 years ago

The ChromeDriver 2.29 is not supporting version 59. We should wait for new release

venkateswaris commented 6 years ago

@Shaihuludus ChromeDriver 2.32 is providing support for headless. Are you providing any support for headless?

reedsexpo commented 6 years ago

@mkrzyzanowski @subiron @mmajchrzak

please can you provide us the headless support for ChromeDriver 2.32 as @venkateswaris request. Please this is a blocker to us in using bobcat as a framework for our automation.

Many Thanks Reed QA

mkrzyzanowski commented 6 years ago

Hi, @venkateswaris and @reedsexpo!

Since we are not providing any version of ChromeDriver bundled with Bobcat, you are free to use the latest version that supports the headless mode in Chrome. To make it work though, a bit of additional code is required. You must add it to your own codebase for now,

To enable headless mode in Chrome

We are going to use CapabilitiesModifier to add the necessary Chrome options and introduce two new properties to control the headless mode:

webdriver.chrome.headless=true
webdriver.chrome.headless.disableGpu=false
public class ChromeOptionsModifier implements CapabilitiesModifier {

  @Inject
  @Named("webdriver.chrome.headless")
  private boolean enabled;

  @Inject
  @Named("webdriver.chrome.headless.disableGpu")
  private boolean disableGpu;

  @Override
  public boolean shouldModify() {
    return enabled;
  }

  @Override
  public Capabilities modify(Capabilities capabilities) {
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.addArguments("headless");
    if(disableGpu) {
      chromeOptions.addArguments("disable-gpu");
    }
    Capabilities chromeCapabilites = DesiredCapabilities.chrome();
    ((DesiredCapabilities)capabilities).setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    return chromeCapabilites.merge(capabilities);
  }
}
public class GuiceModule extends AbstractModule {

  @Override
  protected void configure() {

    install(new CoreModule());

    // other modules or bindings

    Multibinder<CapabilitiesModifier> capabilitiesModifierMultibinder =
        Multibinder.newSetBinder(binder(), CapabilitiesModifier.class);
    capabilitiesModifierMultibinder.addBinding().to(ChromeOptionsModifier.class);
  }
}

Now you can toggle the headless mode using the webdriver.chrome.headless property :).

praveenitgroup commented 6 years ago

Hello @mkrzyzanowski,

I have generated a new 'bobcat-aem-bdd' using gradlew, following the instructions in https://github.com/Cognifide/bobcat-gradle-template

I am able to start the tests on chrome browser as a first step, and this is working.

Secondly, when I tried to execute the tests on headless chrome, by modifying all config.yaml and chrome.yaml properties file, this didn't work. After some research, I found this link and did exactly as mentioned above. And, the tests are still running on chrome browser instead of headless browser.

I am fairly new to bobcat and test automation, not sure what am I doing wrong please suggest,

Steps to reproduce,

  1. Generate 'bobcat-aem-bdd' using gradlew
  2. update the config. yaml with the mentioned properties,

default: properties: proxy.enabled: false proxy.ip: 127.0.0.1 proxy.port: 9000 bobcat.report.path: ./target/report bobcat.report.reporters: html,json,simple,stdout webdriver.defaultTimeout: 10 page.title.timeout: 30 thread.count: 3 webdriver.chrome.headless: true webdriver.chrome.headless.disableGpu: false contexts: [chrome,locator,dev]

  1. Create a new ChromeOptionsModifier.java file in the same package as that of GuiceModule.java and copy the content shown above with the necessary imports,

import org.openqa.selenium.Capabilities; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.DesiredCapabilities; import com.cognifide.qa.bb.provider.selenium.webdriver.modifiers.capabilities.CapabilitiesModifier; import com.google.inject.Inject; import com.google.inject.name.Named;

  1. Modify the GuiceModule.java and add the Multibinder lines shown above, with necessary imports,

import com.cognifide.qa.bb.provider.selenium.webdriver.modifiers.capabilities.CapabilitiesModifier; import com.google.inject.multibindings.Multibinder;

praveenitgroup commented 6 years ago

Hello @mkrzyzanowski,

I have updated the documentation for 'bobcat-gradle-template' on the issues that I encountered, please approve if it is appropriate. https://github.com/Cognifide/bobcat-gradle-template/pull/11

Note: Couldn't add you as reviewer.

vagwada commented 5 years ago

Hi @mkrzyzanowski, Following the instructions above I get the errors below when I try to run on Chrome in headless mode. Any suggestions on how to fix this?

` 1) No implementation for java.lang.Boolean annotated with @com.google.inject.name.Named(value=webdriver.chrome.headless.disableGpu) was bound. while locating java.lang.Boolean annotated with @com.google.inject.name.Named(value=webdriver.chrome.headless.disableGpu) for field at bobcat.ChromeOptionsModifier.disableGpu(ChromeOptionsModifier.java:10) at bobcat.GuiceModule.configure(GuiceModule.java:35)

2) No implementation for java.lang.Boolean annotated with @com.google.inject.name.Named(value=webdriver.chrome.headless) was bound. while locating java.lang.Boolean annotated with @com.google.inject.name.Named(value=webdriver.chrome.headless) for field at bobcat.ChromeOptionsModifier.enabled(ChromeOptionsModifier.java:10) at bobcat.GuiceModule.configure(GuiceModule.java:35) `

mkrzyzanowski commented 5 years ago

Hi @vagwada,

seems like you don't have the properties mentioned in the stack trace in your config. If you are using the latest Bobcat version, 1.6.0, then you should put these in the config.yaml file :).

vagwada commented 5 years ago

Awesome, I'll give that a try, thanks! On Sun, Nov 4, 2018 at 12:59 PM Michał Krzyżanowski < notifications@github.com> wrote:

Hi @vagwada https://github.com/vagwada,

seems like you don't have the properties mentioned in the stack trace in your config. If you are using the latest Bobcat version, 1.6.0, then you should put these in the config.yaml file :).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Cognifide/bobcat/issues/188#issuecomment-435705385, or mute the thread https://github.com/notifications/unsubscribe-auth/AOrJvGRzIDPQ3pI1Ipkzy7UKmPomVXqPks5ur1UxgaJpZM4Na5N4 .

DeChrish commented 5 years ago

@mkrzyzanowski
can we use the same approach for below option?

ChromeOptions options = new ChromeOptions(); options.addArguments("--disable-site-isolation-trials");

Ref: https://bugs.chromium.org/p/chromedriver/issues/detail?id=2660

mkrzyzanowski commented 5 years ago

Done in #314

DeChrish commented 4 years ago

@mkrzyzanowski When it will be released?

mkrzyzanowski commented 4 years ago

Released in 2.2.0