[英]I am using unittest.TestCase if i have more than 1 test case it will not run. Only 1 test case runs
I am automating our website. 我正在自动化我们的网站。 I am using Python, Webdriver, unittest.TestCase
. 我正在使用Python,Webdriver, unittest.TestCase
。
I had 1 test method defined in my Login Page class which is to test a valid user log in. That works fine. 我在Login Page类中定义了1个测试方法,该方法用于测试有效的用户登录。
Now i am adding a 2nd test method called test_login_invalid_user to test an invalid user log in. I am just browsing to the log in page to start with to see if the 2nd test method gets called when i run my test. 现在,我添加了一个名为test_login_invalid_user的第二种测试方法来测试无效的用户登录。我只是浏览到登录页面以开始查看我运行测试时是否调用了第二种测试方法。
When i run my code i get the following error: 当我运行代码时,出现以下错误:
Traceback (most recent call last):
File "C:\Users\riaz.ladhani\PycharmProjects\Selenium Webdriver\ClearCore \LoginPage_TestCase.py", line 40, in test_login_invalid_user
login_page = page.login(self.driver)
AttributeError: 'module' object has no attribute 'login'
Can I not have more than 1 test method in my unit test? 单元测试中可以有不止一种测试方法吗? I am doing it the wrong way? 我做错了吗?
My unit test class code snippet is as follows: 我的单元测试课程代码片段如下:
import unittest
from selenium import webdriver
import page
import time
class LoginPage_TestCase(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Ie("C:\QA\Automation\Python_projects\Selenium Webdriver\IEDriverServer_Win32_2.45.0\IEDriverServer.exe")
self.driver.get("http://riaz-pc.company.local:8080/clearcore")
def test_login_valid_user(self):
login_page = page.LoginPage(self.driver)
login_page.userLogin_valid()
login_page.isAdministration_present()
assert login_page.isAdministration_present(), "Administration not found"
if login_page.isAdministration_present() == "true":
print "test login with a valid user passed"
else:
print "test login with a valid user failed"
def test_login_invalid_user(self):
print "test_login_invalid_user"
login_page = page.login(self.driver)
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()
From what I understand, you meant to define a new LoginPage
page object instance instead: 据我了解,您的意思是定义一个新的LoginPage
页面对象实例:
def test_login_invalid_user(self):
print "test_login_invalid_user"
login_page = page.LoginPage(self.driver)
If this is the case, to avoid violating the "DRY" principle and to improve readability, instantiate LoginPage
in setUp()
: 如果是这种情况,为避免违反“ DRY”原理并提高可读性,请在setUp()
实例化LoginPage
:
class LoginPage_TestCase(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Ie("C:\QA\Automation\Python_projects\Selenium Webdriver\IEDriverServer_Win32_2.45.0\IEDriverServer.exe")
self.driver.get("http://riaz-pc.company.local:8080/clearcore")
self.login_page = page.LoginPage(self.driver)
def test_login_valid_user(self):
self.login_page.userLogin_valid()
self.login_page.isAdministration_present()
assert self.login_page.isAdministration_present(), "Administration not found"
if self.login_page.isAdministration_present() == "true":
print "test login with a valid user passed"
else:
print "test login with a valid user failed"
def test_login_invalid_user(self):
print "test_login_invalid_user"
# use self.login_page here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.