Skip to content

Commit

Permalink
Merge pull request #191 from TeerawatRksp/webdriver-custom-options
Browse files Browse the repository at this point in the history
override webdriver options on webdriverUser with example
  • Loading branch information
cyberw authored Aug 5, 2024
2 parents e9fb76d + f0ae317 commit d9f71e2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
20 changes: 20 additions & 0 deletions examples/webdriver_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@

class MyUser(WebdriverUser):
wait_time = constant(2)
# webdriver client options can be customized by overriding the option_args
option_args = [
"--disable-translate",
"--disable-extensions",
"--disable-background-networking",
"--safebrowsing-disable-auto-update",
"--disable-sync",
"--metrics-recording-only",
"--disable-default-apps",
"--no-first-run",
"--disable-setuid-sandbox",
"--hide-scrollbars",
"--no-sandbox",
"--no-zygote",
"--autoplay-policy=no-user-gesture-required",
"--disable-notifications",
"--disable-logging",
"--disable-permissions-api",
"--ignore-certificate-errors",
]

if __name__ == "__main__":
# wait a bit at the end to make debugging easier
Expand Down
41 changes: 21 additions & 20 deletions locust_plugins/users/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,7 @@ def __init__(self, user: User):
options = Options()
if self.user.headless:
options.add_argument("--headless")
for arg in [
"--disable-translate",
"--disable-extensions",
"--disable-background-networking",
"--safebrowsing-disable-auto-update",
"--disable-sync",
"--metrics-recording-only",
"--disable-default-apps",
"--no-first-run",
"--disable-setuid-sandbox",
"--hide-scrollbars",
"--no-sandbox",
"--no-zygote",
"--autoplay-policy=no-user-gesture-required",
"--disable-notifications",
"--disable-logging",
"--disable-permissions-api",
"--ignore-certificate-errors",
]:
for arg in self.user.option_args:
options.add_argument(arg)
# hide infobar about automation
options.add_experimental_option("excludeSwitches", ["enable-automation"])
Expand Down Expand Up @@ -251,8 +233,27 @@ def failure(self, exc):
class WebdriverUser(User):
abstract = True
_first_instance = True
headless = False # overwrite this as needed
command_executor = "http://127.0.0.1:4444"
headless = False # overwrite this as needed
option_args = [ # overwrite this as needed
"--disable-translate",
"--disable-extensions",
"--disable-background-networking",
"--safebrowsing-disable-auto-update",
"--disable-sync",
"--metrics-recording-only",
"--disable-default-apps",
"--no-first-run",
"--disable-setuid-sandbox",
"--hide-scrollbars",
"--no-sandbox",
"--no-zygote",
"--autoplay-policy=no-user-gesture-required",
"--disable-notifications",
"--disable-logging",
"--disable-permissions-api",
"--ignore-certificate-errors",
]

def __init__(self, parent):
super().__init__(parent)
Expand Down

0 comments on commit d9f71e2

Please sign in to comment.