首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在python webdriver脚本中使用ExtentReports时出错

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

Stack Overflow用户
提问于 2017-04-07 16:35:55
回答 1查看 1.4K关注 0票数 0

使用ExtentReports可以在selenium java web驱动脚本中生成良好且丰富的超文本标记语言测试报告。我正在尝试使用JPype在我的selenium python web驱动程序脚本中使用它(JPype是一种允许python程序完全访问java类库的努力)。我的代码是这样的

代码语言:javascript
复制
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()

它会给出错误

代码语言:javascript
复制
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更新121中使用的Python

有人能帮上忙吗?

EN

回答 1

Stack Overflow用户

发布于 2017-06-01 18:36:55

我知道答案了。以下代码将正常工作:

代码语言:javascript
复制
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()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43273447

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档