在使用Jpyp的python webdriver脚本中使用ExtentReports时出错

2024-06-06 07:43:58 发布

您现在位置:Python中文网/ 问答频道 /正文

ExtentReports可以在selenium java web驱动程序脚本中使用,以生成好的、丰富的HTML测试报告。我试图在我的selenium python web驱动程序脚本中使用JPype(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()

它会出错

^{pr2}$

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

有人能帮忙吗?在


Tags: test脚本comwebselenium驱动程序jpypejava
1条回答
网友
1楼 · 发布于 2024-06-06 07:43:58

我知道答案了。以下代码将起作用:

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

相关问题 更多 >