1

イナゴが自分の Web アプリケーションにログインして、Web アプリケーション内のリンクをクリックできるようにしたいと考えています。

このコードを使用すると、ログインでフロントページのアクティビティを取得するだけで、アプリケーション内から通知を受け取ることはありません。

コード:

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


class WalkPages(TaskSet):
    def on_start(self):
        self.client.post("/", {
            "UserName": "my@email.com",
            "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

最初のラウンドの後、端末に次のメッセージが表示されます。

[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
4

2 に答える 2

0

時間はかかりますが、誰かがこれを必要とするかもしれません。あなたのコードでの私の発見:ログインリクエストは正しくないようです(正しい場合は私のものをチェックしてください)、別の関数から関数内で定義された変数に到達できず、データセッター関数task(10)には適していません。urls_on_current_page をクラス変数として設定して、他のクラス メンバーに提供します。私のコードとコメントを見てください:

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


class WalkPages(TaskSet):
    # define variable here to access them from inside the functions
    urls_on_current_page = []

    def login(self):
        self.client.post("/login", data = {"UserName": "mesutgunes@email.com", "Password": "password"})

    def get_urls(self):
        r = self.client.get("/Dashboard.mvc")
        pq = PyQuery(r.content)
        link_elements = pq("a")
        for link in link_elements:
            if key in link.attrib and "http" not in link.attrib[key]: 
            # there maybe external link on the page
                self.urls_on_current_page.append(link.attrib[key])


    def on_start(self):
        self.login()
        self.get_urls()


    @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
于 2015-10-13T05:24:28.803 に答える