Note that there are some explanatory texts on larger screens.

plurals
  1. POUnittest with selenium works flawlessy in python but gives import error with django manage.py test
    text
    copied!<p>I have this file, generated from Selenium IDE</p> <pre><code>from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException import unittest, time, re class Tcase(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() self.driver.implicitly_wait(30) self.base_url = "http://localhost:9999/" self.verificationErrors = [] def test_tcase(self): driver = self.driver driver.get(self.base_url) # other things... def is_element_present(self, how, what): try: self.driver.find_element(by=how, value=what) except NoSuchElementException, e: return False return True def tearDown(self): self.driver.quit() self.assertEqual([], self.verificationErrors) if __name__ == "__main__": unittest.main() </code></pre> <p>I'm working on a Django project (1.4) and python 2.6, which i want to test with Selenium.</p> <p>if i run this file directly from python it works without problems.</p> <p>if i run this doing</p> <pre><code>python manage.py test myapp </code></pre> <p>i get import error</p> <pre><code>C:\web\opineo&gt; python .\manage.py test core Traceback (most recent call last): File ".\manage.py", line 14, in &lt;module&gt; execute_manager(settings) File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 459, in execute_manager utility.execute() File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 382, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python26\lib\site-packages\django\core\management\commands\test.py", line 49, in run_from_argv super(Command, self).run_from_argv(argv) File "C:\Python26\lib\site-packages\django\core\management\base.py", line 196, in run_from_argv self.execute(*args, **options.__dict__) File "C:\Python26\lib\site-packages\django\core\management\base.py", line 232, in execute output = self.handle(*args, **options) File "C:\Python26\lib\site-packages\south-0.7.3-py2.6.egg\south\management\commands\test.py", line 8, in handle super(Command, self).handle(*args, **kwargs) File "C:\Python26\lib\site-packages\django\core\management\commands\test.py", line 72, in handle failures = test_runner.run_tests(test_labels) File "C:\Python26\lib\site-packages\django\test\simple.py", line 380, in run_tests suite = self.build_suite(test_labels, extra_tests) File "C:\Python26\lib\site-packages\django\test\simple.py", line 264, in build_suite suite.addTest(build_suite(app)) File "C:\Python26\lib\site-packages\django\test\simple.py", line 79, in build_suite test_module = get_tests(app_module) File "C:\Python26\lib\site-packages\django\test\simple.py", line 36, in get_tests test_module = import_module('.'.join(prefix + [TEST_MODULE])) File "C:\Python26\lib\site-packages\django\utils\importlib.py", line 35, in import_module __import__(name) File "C:\web\opineo\core\tests\__init__.py", line 3, in &lt;module&gt; from core.tests.func import * File "C:\web\opineo\core\tests\func.py", line 1, in &lt;module&gt; from selenium import webdriver File "C:\web\opineo\core\tests\selenium.py", line 3, in &lt;module&gt; from selenium import webdriver ImportError: cannot import name webdriver </code></pre> <p>what's wrong? the selenium files are there! in site-packages of Python 2.6</p> <p><strong>EDIT:</strong></p> <p>this works, as expected it opens Firefox</p> <pre><code>PS C:\web\opineo&gt; python.exe .\manage.py shell Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32 &gt;&gt;&gt; from selenium import webdriver &gt;&gt;&gt; driver = webdriver.Firefox() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload