Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error to login to webapp in Locust #246

Closed
casidos opened this issue Feb 16, 2015 · 3 comments
Closed

Error to login to webapp in Locust #246

casidos opened this issue Feb 16, 2015 · 3 comments

Comments

@casidos
Copy link

casidos commented Feb 16, 2015

I want locust to be able to login to my web application and start to click in the links inside the web application.

With this code I just get activity for the front page with the login and i don't get any notification from inside the application.

Code:

import random
from locust import HttpLocust, TaskSet, task
from pyquery import PyQuery

class WalkPages(TaskSet):
    def on_start(self):
        self.client.post("/", {
            "UserName": "[email protected]",
            "Password": "2Password!",
            "submit": "Sign In"
        })
       self.index_page()

@task(10)
def index_page(self):
    r = self.client.get("/Dashboard.mvc")
    pq = PyQuery(r.content)
    link_elements = pq("a")
    self.urls_on_current_page = []
    for l in link_elements:
      if "href" in l.attrib:
        self.urls_on_current_page.append(l.attrib["href"])

@task(30)
def load_page(self):
    url = random.choice(self.urls_on_current_page)
    r = self.client.get(url)


class AwesomeUser(HttpLocust):
    task_set = WalkPages
    host = "https://myenv.beta.webapp.com"
    min_wait = 20  * 1000
    max_wait = 60  * 1000

I get the follow msg in the terminal after the first round.

[2015-02-13 12:08:43,740] webapp-qa/ERROR/stderr: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/locust/core.py", line 267, in run
self.execute_next_task()
File "/usr/local/lib/python2.7/dist-packages/locust/core.py", line 293, in execute_next_task
self.execute_task(task["callable"], _task["args"], *_task["kwargs"])
File "/usr/local/lib/python2.7/dist-packages/locust/core.py", line 305, in execute_task
task(self, _args, *_kwargs)
File "/home/webapp/LoadTest/locustfile.py", line 31, in load_page
url = random.choice(self.urls_on_current_page)
File "/usr/lib/python2.7/random.py", line 273, in choice
return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty
IndexError: list index out of range
[2015-02-13 12:08:43,752] webapp-qa/ERROR/stderr: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/locust/core.py", line 267, in run
self.execute_next_task()
File "/usr/local/lib/python2.7/dist-packages/locust/core.py", line 293, in execute_next_task
self.execute_task(task["callable"], _task["args"], *_task["kwargs"])
File "/usr/local/lib/python2.7/dist-packages/locust/core.py", line 305, in execute_task
task(self, _args, *_kwargs)
File "/home/webapp/LoadTest/locustfile.py", line 31, in load_page
url = random.choice(self.urls_on_current_page)
File "/usr/lib/python2.7/random.py", line 273, in choice
return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty
IndexError: list index out of range
[2015-02-13 12:08:43,775] webapp-qa/ERROR/stderr: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/locust/core.py", line 267, in run
self.execute_next_task()
File "/usr/local/lib/python2.7/dist-packages/locust/core.py", line 293, in execute_next_task
self.execute_task(task["callable"], _task["args"], *_task["kwargs"])
File "/usr/local/lib/python2.7/dist-packages/locust/core.py", line 305, in execute_task
task(self, _args, *_kwargs)
File "/home/webapp/LoadTest/locustfile.py", line 31, in load_page
url = random.choice(self.urls_on_current_page)
File "/usr/lib/python2.7/random.py", line 273, in choice
return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty
IndexError: list index out of range

@echorohit
Copy link

I am also facing same error,

[2015-07-31 15:51:23,258] JADEHOL1366/ERROR/stderr: Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/locust/core.py", line 264, in run self.schedule_task(self.get_next_task()) File "/usr/local/lib/python2.7/dist-packages/locust/core.py", line 325, in get_next_task return random.choice(self.tasks) File "/usr/lib/python2.7/random.py", line 273, in choice return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty IndexError: list index out of range

@kunalg
Copy link

kunalg commented Aug 21, 2015

@casidos this part of the error list clearly says what's wrong:

File "/home/webapp/LoadTest/locustfile.py", line 31, in load_page
url = random.choice(self.urls_on_current_page)
File "/usr/lib/python2.7/random.py", line 273, in choice
return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty
IndexError: list index out of range

It means that the list you're trying to build - self.urls_on_current_page - is empty.

@echorohit did you decorate your tasks with the @task decorator?
Without that, it never queues up the tasks and hence the error.

@justiniso
Copy link
Member

Your tasks need to be methods of the WalkPages class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants