SvenskaSpel / locust-plugins

A set of useful plugins/extensions for Locust
Apache License 2.0
526 stars 136 forks source link

Browser is not starting in headless mode #162

Closed kolo-vrat closed 5 months ago

kolo-vrat commented 5 months ago

As mentioned in the title the browser does not start in headless mode despite overriding the headless user class variable. After inspecting the Selenium Server logs I noticed that the --headless option is not passed down. The issue can be fixed if the --headless option is added as an argument to the options instead of assigning it as a property.

Here is portion of the logs:

12:51:48.865 INFO [LocalDistributor.newSession] - Session request received by the Distributor: 
 [Capabilities {acceptInsecureCerts: true, browserName: chrome, goog:chromeOptions: {args: [--disable-translate, --disable-extensions, --disable-background-networ..., --safebrowsing-disable-auto..., --disable-sync, --metrics-recording-only, --disable-default-apps, --no-first-run, --disable-setuid-sandbox, --hide-scrollbars, --no-sandbox, --no-zygote, --autoplay-policy=no-user-g..., --disable-notifications, --disable-logging, --disable-permissions-api, --ignore-certificate-errors], excludeSwitches: [enable-automation], extensions: []}, pageLoadStrategy: eager}]
12:51:50.739 INFO [LocalNode.newSession] - Session created by the Node. Id: 4b29f0e02bb7d3f731c8ef7c865f74fc, Caps: Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 120.0.6099.199, chrome: {chromedriverVersion: 120.0.6099.109 (3419140ab66..., userDataDir: /tmp/.org.chromium.Chromium...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:44391}, networkConnectionEnabled: false, pageLoadStrategy: eager, platformName: linux, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://192.168.0.14:4444/sess..., se:cdpVersion: 120.0.6099.199, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}

Environment

OS

Ubuntu 22.04.3 LTS x86_64

Python

3.11.7

Selenium Server

selenium-server-4.16.1.jar

Chrome WebDriver

120.0.6099.109

Packages

locust==2.20.1
locust-plugins==4.3.2
selenium==4.16.0

Code

Here is my locustfile.py

class MyUser(WebdriverUser):  
    wait_time = constant(2)  
    headless = True  
    tasks = [Tasks]

Fix

I fixed this issue by modifying the locust_plugins/users/webdriver.py file.

From:

options.headless = self.user.headless

To:

if self.user.headless:
    options.add_argument("--headless")
cyberw commented 5 months ago

I have kind of given up on the webdriver stuff (instead using playwright, if any browser tests at all..), but if you make a PR I will be happy to merge it :)