attributeError:' htmltestresult'对象没有属性' _count_relevant_tb_levels'。您的意思是:' _is_relevant_tb_level&#x27 ;?

发布于 2025-01-21 11:10:42 字数 1119 浏览 0 评论 0原文

导入UNITSEST 导入htmltestrunner 来自Selenium Import Webdriver class test_orangehrm(unittest.testcase): @ClassMethod Def SetupClass(CLS): options = webdriver.chromeoptions() options.add_experimenty_option('excludesWitches',['enable-logging']) cls.driver = webdriver.chrome(options = options) cls.driver.maximize_window() def test_homepage(self): self.driver.get(“ https://opensource-demo.orangehrmlive.com/”) 如果名称

def test_Login(self):
    self.driver.get("https://opensource-demo.orangehrmlive.com/")
    self.driver.find_element_by_xpath("//*[@id='txtUsername']").send_keys("Admin")
    self.driver.find_element_by_xpath("//*[@id='txtPassword']").send_keys("admin123")
    self.driver.find_element_by_xpath("//*[@id='btnLogin']").click()
    self.assertEqual("OrangeHRM123", self.driver.title, "Webpage Title Is Not Matching")
@classmethod
def tearDownClass(cls):
    cls.driver.quit()
    print("Test Completed")

==“ main ”: UNITTEST.MAIN(testRunner = htmltestrunner.htmltestrunner(output =“ c:/users/hp/pycharmprojects/seleniumpython/Reports)))))

import unittest
import HtmlTestRunner
from selenium import webdriver
class Test_OrangeHRM(unittest.TestCase):
@classmethod
def setUpClass(cls):
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
cls.driver = webdriver.Chrome(options=options)
cls.driver.maximize_window()
def test_HomePage(self):
self.driver.get("https://opensource-demo.orangehrmlive.com/")
self.assertEqual("OrangeHR", self.driver.title, "Webpage Title Is Not Matching")

def test_Login(self):
    self.driver.get("https://opensource-demo.orangehrmlive.com/")
    self.driver.find_element_by_xpath("//*[@id='txtUsername']").send_keys("Admin")
    self.driver.find_element_by_xpath("//*[@id='txtPassword']").send_keys("admin123")
    self.driver.find_element_by_xpath("//*[@id='btnLogin']").click()
    self.assertEqual("OrangeHRM123", self.driver.title, "Webpage Title Is Not Matching")
@classmethod
def tearDownClass(cls):
    cls.driver.quit()
    print("Test Completed")

if name=="main":
unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output="C:/Users/HP/PycharmProjects/seleniumPython/Reports"))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一场春暖 2025-01-28 11:10:42

这对我有用。
显然,“ _Count_Relevant_tb_levels”在最新版本中不可用,因此您需要转到HTMLTestrunner软件包的源代码。

  1. 在您已安装的软件包的HTMLTestrunner文件夹中,寻找result.py

  2. 替换这些行:

     如果ExCtype是test.failureexception:
         #跳过*()追溯级别
         长度= self._count_relevant_tb_levels(tb)
         msg_lines = trackback.format_exception(Exctype,value,tb,length)
     

    if exctype is test.failureException:
        # Skip assert*() traceback levels
        msg_lines = traceback.format_exception(exctype, value, tb)

This works for me.
Apparently the "_count_relevant_tb_levels" is not available in the newest versions, so you need to go to the source code of the HtmlTestRunner package.

  1. Inside the HtmlTestRunner folder of the package you have installed, look for result.py

  2. Find the "_exc_info_to_string" method of the "HtmlTestResult" class.

  3. Replace these lines:

     if exctype is test.failureException:
         # Skip assert*() traceback levels
         length = self._count_relevant_tb_levels(tb)
         msg_lines = traceback.format_exception(exctype, value, tb, length)
    

with

    if exctype is test.failureException:
        # Skip assert*() traceback levels
        msg_lines = traceback.format_exception(exctype, value, tb)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文