python - 如何在 Python Webdriver 中运行 1 个以上的测试用例。我的测试用例类中只有 1 个运行

标签 python selenium selenium-webdriver webdriver

在我的自动化页面对象模型脚本中,到目前为止我已经使用一些测试用例和方法创建了 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 配置为: enter image description here

关于python - 如何在 Python Webdriver 中运行 1 个以上的测试用例。我的测试用例类中只有 1 个运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30298426/

相关文章:

javascript - Selenium 和Python : explicit wait for postback in select (wait for Javascript with Selenium)

selenium - 如何在 Selenium Chromedriver 中加载 URL 之前发送 key ?

python selenium webscraping "NoSuchElementException"无法识别

python - 这里导入错误的具体原因是什么?

java - 如何强制 AutoClosable 警告传播到 Java 类的调用者?

Android Python 获取gps状态

html - Selenium:嵌入到 Object 标签中的 SVG 元素未被 Selenium IDE 或 xPath 识别?

java - 如何在 Java 或 Android 项目中添加 Selenium 库。 import org.openqa 无法解析

python - 使用版本控制 : versioned url retrieval 的 DRF 测试 View

python - 有没有办法用正则表达式循环遍历列表?