0

I'm getting an ImportError attempting to run a Locust/Selenium script: ImportError: cannot import name 'StopLocust' from 'locust.exception'

Is there a package that I need to install?

from realbrowserlocusts import ChromeLocust
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from locust_plugins.users import WebdriverUser
from locust.exception import StopLocust
import os
from locust import TaskSet, task

The output from the Terminal window shows this: File "c:\users\mjohns33\pycharmprojects\omni\lib\site-packages\realbrowserlocusts\core.py", line 6, in from locust.exception import StopLocust ImportError: cannot import name 'StopLocust' from 'locust.exception' (c:\users\mjohns33\pycharmprojects\omni\lib\site-packages\locust\exception.py)

Any ideas?

4 Answers4

2

If you're using Locust 1.0+ there is no StopLocust in locust.exceptions. I'm not sure what it is you're looking to do so I don't know if it's the right thing for you to use, but there is StopUser in there that you should be able to import.

Solowalker
  • 2,431
  • 8
  • 13
  • I'm using locust version1.4.0. I'm attempting to run a selenium script via Locust and I'm running into import error. from locust import TaskSet, task class LocustUserBehavior(TaskSet): def open_agent_homepage(self): self.client.get("https://stg-wwe.uhc.com/ui/ad/v1/index.html") #self.client.wait.until(EC.visibility_of_element_located((By.XPATH, '//a[text()="Documentation"]')), "documentation link is visible") etc... – Michael Johnson Nov 16 '20 at 18:00
  • Sure, I get that you're running into the import error. My answer should fix that for you. I don't know why you're trying to import StopLocust/StopUser, though. What are you trying to do with those? – Solowalker Nov 16 '20 at 19:34
  • I'm not aware of how I'm importing the StopLocust command. If you look at all my import functions StopLocust isn't one of them. – Michael Johnson Dec 09 '20 at 22:49
  • In your original post you have `from locust.exception import StopLocust`. Not sure if you were experiencing other import issues, but that's the one you originally posted about so that's what my answer was addressing. – Solowalker Dec 09 '20 at 23:05
  • The original script was fixed without the import StopLocust. I also have another Dev/QA looking into it and he's getting the same error message. – Michael Johnson Dec 10 '20 at 02:56
  • The fix is downgrading locust to v0.13.5. The latest version of Locust isn't compatible with realbrowserlocusts. – Michael Johnson Jan 15 '21 at 18:02
1

After doing some more research I was able to resolve a couple of issues from the import error. Installing locustio solved the import issue and a follow-on issue in attempting to load the locust web page was solved by updating gevent.

So, for the full fix uninstall the current version of locust and install the locustio version. Then upgrade the gevent.

pip uninstall locust pip install locustio==0.14.6 pip install --upgrade gevent

0

Local environment issue. Re-installing my setup.

0

Realbrowserlocusts isn't compatible with the most recent versions of Locust. Downgrading to version locust 0.13.5 fixed the issue. I'm not sure exactly which of the most recent versions of locust supports realbrowserlocusts. I would like to find out though so I'm running the best of locust versions supporting running with selenium.