【问题标题】:Error while using ExtentReports in python webdriver script using Jpype使用 Jpype 在 python webdriver 脚本中使用 ExtentReports 时出错
【发布时间】:2017-09-02 13:29:48
【问题描述】:

ExtentReports 可以在 selenium java web-driver 脚本中使用,以生成良好且丰富的 HTML 测试报告。我正在尝试使用 JPype 在我的 selenium python web-driver 脚本中使用它(JPype 是为了让 python 程序完全访问 java 类库)。 我的代码就像

from jpype import *
classpath = """lib\\extentreports-2.41.2.jar;lib\\freemarker-2.3.23.jar"""
startJVM(getDefaultJVMPath(), "-Djava.class.path=%s" % classpath)
ExtentReports = JClass('com.relevantcodes.extentreports.ExtentReports')
ExtentTest = JClass('com.relevantcodes.extentreports.ExtentTest')
LogStatus = JClass('com.relevantcodes.extentreports.LogStatus')
extent = ExtentReports("TestResult\\Test_Report.html")
test = extent.startTest("My First Test", "Sample description")
test.log(LogStatus.INFO, "This step shows usage of log(logStatus, details)")
extent.endTest(test)
extent.flush()
shutdownJVM()

它给出了错误

Traceback (most recent call last):
File "C:\Users\test\workspace\ExtentReportsProject\ExtentReportsPackage\report.py", line 4, in <module>
ExtentReports = JClass('com.relevantcodes.extentreports.ExtentReports')
File "C:\Program Files\Python35\lib\site-packages\jpype1-0.6.2-py3.5-win-amd64.egg\jpype\_jclass.py", line 55, in JClass
raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name)
jpype._jexception.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class com.relevantcodes.extentreports.ExtentReports not found

我正在使用 extentreports-2.41.2.jar 和 freemarker-2.3.23.jar。 3.5.1 和 Java 8 中使用的 Python 更新 121

有人可以帮忙吗?

【问题讨论】:

  • 有什么解决办法吗?

标签: python selenium-webdriver jpype


【解决方案1】:

我得到了答案。以下代码将起作用:

from jpype import *

classpath = """extentreports-2.40.2.jar;freemarker-2.3.23.jar"""
startJVM(getDefaultJVMPath(), "-Djava.class.path=%s" % classpath)
ExtentReports = JClass('com.relevantcodes.extentreports.ExtentReports')
ExtentTest = JClass('com.relevantcodes.extentreports.ExtentTest')
LogStatus = JClass('com.relevantcodes.extentreports.LogStatus')
extent = ExtentReports("Test_Report.html")

test = extent.startTest("Test Case 1", "Sample description")
test.log(LogStatus.INFO, "This step shows usage of log(logStatus, details)")
test.log(LogStatus.PASS, "Step Passed")
extent.flush()

test = extent.startTest("Test Case 2", "Sample description")
test.log(LogStatus.INFO, "This step shows usage of log(logStatus, details)")
test.log(LogStatus.PASS, "")
test.log(LogStatus.FAIL, "Step Passed")
extent.flush()

extent.endTest(test)
extent.flush()
shutdownJVM()

【讨论】:

    猜你喜欢
    • 2013-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-16
    • 2011-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多