在我的自动化页面对象模型脚本中,到目前为止我已经使用一些测试用例和方法创建了 2 个测试用例。
类 LoginPage_TestCase(unittest.TestCase):
类 AdministrationPage_TestCase(unittest.TestCase):
LoginPage 有一个用于测试有效用户登录的测试
AdministrationPage 目前有 1 个方法 add_Project(用户可以在登录后添加项目)
在 PyCharm 编辑器中,我打开了 AdministrationPage。我单击绿色运行图标来运行测试用例。在继续编写更多方法之前,我想看看我的方法 add_project 是否有效。
当测试运行时,它会运行 LoginPage 测试用例,然后停在那里。
如何运行 AdministrationPage 测试用例?
另外,如果我想先运行 LoginPage 测试用例,然后在 LoginPage 完成时运行 AdministrationPage。我怎样才能做到这一点?谢谢!
我的登录页面和管理页面的代码片段如下:
LoginPage_TestCase.py
from selenium import webdriver
from Pages import page
from Locators import locators
from Locators import element
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)
self.driver.implicitly_wait(30)
def test_login_valid_user(self):
print "test_login_valid_user"
login_page = page.LoginPage(self.driver)
login_page.userLogin_valid()
login_page.isAdministration_present()
print login_page.isAdministration_present()
assert login_page.isAdministration_present(), "Administration link not found"
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()
管理页面_TestCase.py
import unittest
import time
from selenium import webdriver
from locators import locators
from locators import element
from Pages import page
from Pages.administrationPage import AdministrationPage
from Pages.page import LoginPage
class AdministrationPage_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)
print "I am here in setUp self.login_page = page.LoginPage(self.driver)"
self.driver.implicitly_wait(30)
def add_Project(self):
login_page = page.LoginPage(self.driver)
login_page.userLogin_valid()
administration_page = login_page.clickAdministration(self.driver)
administration_page.AdministrationPage.add_project()
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()
管理页面.py
from selenium.common.exceptions import NoSuchElementException
from Locators.locators import MainPageLocators
from Locators import locators
from Locators import element
from Locators.element import BasePageElement
class BasePage(object):
def __init__(self, driver):
self.driver = driver
class AdministrationPage(BasePage):
# Add a project, enter project name & description, save
def add_project(self):
add_project_button = self.driver.find_element(*MainPageLocators.addButton_project)
add_project_button.click()
project_name_textfield = self.driver.find_element(*MainPageLocators.projectName_textfield)
project_name_textfield.click()
project_name_textfield.clear()
project_name_textfield.sendkeys('LADEMO_IE_nn_')
project_description_textfield = self.driver.find_element(*MainPageLocators.projectDescription_textfield)
project_description_textfield.click()
project_description_textfield.clear()
project_name_textfield.sendkeys("LADEMO create a basic project test script - Selenium Webdriver/Python Automated test")
1) 您的测试方法应以 test_
开头。
2) 您应该将 pycharm 配置为:
我是一名优秀的程序员,十分优秀!