-
-
Save algotrader-dotcom/15259b8273e2f264e9c94683a09bde82 to your computer and use it in GitHub Desktop.
Log in to Drupal 8 with locust.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from locust import HttpLocust, TaskSet, task | |
from bs4 import BeautifulSoup | |
class WebsiteTasks(TaskSet): | |
def on_start(self): | |
""" | |
on_start is called when a Locust start before, | |
any task is scheduled | |
""" | |
self.login() | |
def login(self): | |
# Get form build ID to pass back to Drupal on login. | |
resp = self.client.get("/user") | |
parsed_html = BeautifulSoup(resp.content) | |
form_build_id = parsed_html.body.find('input', {'name': 'form_build_id'})['value'] | |
self.client.post("/user/login", { | |
"name": "LoadTester", | |
"pass": "test", | |
"form_id": "user_login_form", | |
"form_build_id": form_build_id, | |
"op": "Log in" | |
}) | |
# Add some pages to load. | |
@task | |
def index(self): | |
self.client.get("/") | |
@task | |
def search(self): | |
self.client.get("/another/page") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment