Locust: URL requests containing “/#/” are all seen as “/” then failing when running on Locust.io

Created on 29 Mar 2018  ·  4Comments  ·  Source: locustio/locust

The requests containing "/#/" are all seen as "/". Then I'll get a ton of "fails".

from locust import HttpLocust, TaskSet, task
class UserBehavior(TaskSet):

@task(2)
def login_page(self):
    self.client.get("/")

@task(1)
def dashboard_page(self):
    self.client.get("/#/bubblesu")

@task(1)
def parents_page(self):
    self.client.get("/#/pages/parents")

class WebsiteUser(HttpLocust):
    task_set = UserBehavior

This is the result
image

There's no cmd errors in the prompt.

Then I tried to convince locust to name (and use) the proper ones. However naming worked, but it looks like the request are still made against "/". So in result I'm not able to load test each request.

My developer says "The hash sign is there because it's a single page application the path after that is just for routing via javascript. if you remove it the browser would try and find the page"

Here's the script

from locust import HttpLocust, TaskSet, task

class UserBehavior(TaskSet):

    @task(2)
    def login_page(self):
        self.client.get("/")

    @task(1)
    def dashboard_page(self):
        self.client.get("/#/bubblesu", name='dashboard')

    @task(1)
    def parents_page(self):
        self.client.get("/#/pages/parents", name='parents')

class WebsiteUser(HttpLocust):
    task_set = UserBehavior

Executing with this from cmd.
locust -f locustfile2.py --host=https://www.bubblesu.com

This is the URL to the login page.
https://bubblesu.com/#/bubblesu

This is what Locust shows.
image

cmd has no errors displayed.

Using Windows 10, Pycharm

All 4 comments

Another way of stating the problem.

Let's assume you have the locustfile described above.

Run this Flask mini-app to determine where the request really go (it just echoes URLs it receives):

from flask import Flask
app = Flask(__name__)

@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catch_all(path):
    return('You want path: %s' % path)

if __name__ == '__main__':
    app.run()    

Run the app:

FLASK_APP=echo.py flask run

And run locust against this app: locust -f locustfile.py --host=http://localhost:5000/

It turns out, that Locust cuts the requested URL just after '#'. This way /#/bubblesu becomes /, etc.

On the other hand, it may be some "pythonic requests/flask issue".

If you do curl localhost:5000/#/test you will also notice, that on flask side the URL is truncated (after #).
Maybe it is some kind of a clue... ;-)

Looks the problem was noticed before: https://github.com/locustio/locust/issues/187

On the other hand, it's worth considering if testing single page applications this way (described in the issue) is really a way to go...

I think Locust (well, actually Requests library) is handling this properly.

in the URL "http://foo/bar#baz", you have a network resource (URI) named "http://foo.bar/bar#" followed by a Fragment.

hash sign ("#") is the Fragment Identifier. The actual URI is everything up to and including the hash sign. Everything after the hash is the optional Fragment, which is not sent in HTTP requests.

From Wikipedia:

"Fragments depend on the document MIME type and are evaluated by the client (Web browser). Clients are not supposed to send URI-fragments to servers when they retrieve a document"

"When an agent (such as a Web browser) requests a web resource from a Web server, the agent sends the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent processes the resource according to the document type and fragment value."


Thanks for the resourses @cgoldberg and @karol-brejna-i.

Just for the heck of it I tried adding percent-encode and it didn't bite.

Thanks for the quick responses. I'll close the issue.

Was this page helpful?
0 / 5 - 0 ratings