Created
April 6, 2017 21:59
-
-
Save acrollet/ebe54e7f4dc9146ebd9ed62155f19a21 to your computer and use it in GitHub Desktop.
Log in to Drupal 8 with locust.io
This file contains 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
I needed to add this at the bottom for it to work