【问题标题】:Trouble getting python selenium tests to run无法运行 python selenium 测试
【发布时间】:2016-07-22 20:46:36
【问题描述】:

我正在使用 selenium 和 python 从头开始​​创建一个自动化框架,并且非常希望获得一些关于最佳方式的输入和建议。

到目前为止,我有以下内容,但我的测试脚本无法运行。请帮忙!

脚本.py

from selenium import webdriver


class WebDriver(object):

  def __init__(self, driver=None):
    """
    __init__ setup webdriver test script class
    """
    self.driver = driver


  def setup(self):
    self.driver = webdriver.Chrome()

  def teardown(self):
    self.driver.quit()

test.py

import script

class Test(script.WebDriver):

  def search(self):
    self.driver.get("www.google.com")
    self.driver.find_element_by_id("lst-ib").clear()

【问题讨论】:

  • “不会运行”是什么意思?有例外吗?有什么要显示的日志吗?
  • 没有错误,只是没有打开浏览器。什么都没有发生
  • 似乎没有任何东西试图创建Test 的实例。这是你所有的代码吗?您如何运行测试 - 直接使用 python test.py 或间接通过测试框架?
  • 直接用python test.py

标签: python selenium automation automated-tests ui-automation


【解决方案1】:

我假设您正在尝试使用python unittest 运行它。如果是这样,您的类应该继承自 unittest.TestCase 以标记它包含测试用例:

class WebDriver(unittest.TestCase)

...

class Test(script.WebDriver)

第二个缺失部分是test.py 中的“运行测试套件的样板代码”(参见解释here):

if __name__ == "__main__":
   test.main()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 2021-03-17
    • 2017-05-25
    • 2021-05-24
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多