我如何在 Python Webdriver 中 运行 超过 1 个测试用例。我的测试用例只有 1 个 class 运行s

How do i run more than 1 Test Case in Python Webdriver. Only 1 of my test case class runs

到目前为止,在我的自动化页面对象模型脚本中,我已经创建了 2 个带有一些测试用例和方法的测试用例。

class LoginPage_TestCase(unittest.TestCase):

class AdministrationPage_TestCase(unittest.TestCase):

LoginPage 有一个测试有效用户登录的测试

AdministrationPage 目前有 1 个方法add_Project(用户可以在登录后添加项目)

在 PyCharm 编辑器中,我打开了 AdministrationPage。我单击绿色 运行 图标以 运行 测试用例。在继续编写更多方法之前,我想看看我的方法 add_project 是否有效。

当测试 运行 是 LoginPage 测试用例时 运行 然后它就停在那里。

如何 运行 AdministrationPage 测试用例?

此外,如果我想先 运行 LoginPage 测试用例,然后在 LoginPage 完成时将 AdministrationPage 运行。我怎样才能做到这一点? 谢谢!

我的代码是 LoginPage 和 AdministraionPage 的代码片段如下:

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()

AdministrationPage_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()

AdministrationPage.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 配置为: