【发布时间】:2019-04-18 16:07:36
【问题描述】:
Red.xml - 使用“添加 Java 库”按钮上传 Java jar 文件时出现此错误。
没有为“Library.class.name”生成库规范文件 图书馆
尝试了以下步骤,
- 从 Eclipse 中自动删除构建并执行项目 -> 清理
- 重新导出了java类文件的jar文件。
注意:从 Shell 脚本构建时,我能够成功构建和执行相同的代码。 在构建类文件时的某个地方会出现此问题。但不确定如何纠正它。
重新加载引用的库类文件时,收到以下错误,
库规范生成问题
Problem occurred during generating libdoc for 'com.KTOC.TRB.testautomation.ObjectRepository.pg_SF_Login' library located at '/Users/roja/Automation/Jars-For-KTOC/TRBJars1.jar'.
RED python session problem. Following exception has been thrown by python service:
Traceback (most recent call last):
File "/var/folders/dv/nnfc_k29377bv7s34kng7qgh0000gn/T/RobotTempDir8808901746972554502/robot_session_server.py", line 38, in inner
result['result'] = func(*args, **kwargs)
File "/var/folders/dv/nnfc_k29377bv7s34kng7qgh0000gn/T/RobotTempDir8808901746972554502/robot_session_server.py", line 84, in inner
return to_call(*args, **kwargs)
File "/var/folders/dv/nnfc_k29377bv7s34kng7qgh0000gn/T/RobotTempDir8808901746972554502/robot_session_server.py", line 116, in inner
return to_call(*args, **kwargs)
File "/var/folders/dv/nnfc_k29377bv7s34kng7qgh0000gn/T/RobotTempDir8808901746972554502/robot_session_server.py", line 59, in inner
return func(*args, **kwargs)
File "/var/folders/dv/nnfc_k29377bv7s34kng7qgh0000gn/T/RobotTempDir8808901746972554502/robot_session_server.py", line 305, in create_libdoc
return red_libraries.create_libdoc(libname, format)
File "/private/var/folders/dv/nnfc_k29377bv7s34kng7qgh0000gn/T/RobotTempDir8808901746972554502/red_libraries.py", line 64, in create_libdoc
raise Exception(result)
Exception: Importing test library 'com.KTOC.TRB.testautomation.ObjectRepository.pg_SF_Login' failed: NoClassDefFoundError: Could not initialize class com.KTOC.TRB.testautomation.ObjectRepository.pg_SF_Login
java.lang.NoClassDefFoundError:
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at robot.utils.importer$py._import$14(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/utils/importer.py:167)
at robot.utils.importer$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/utils/importer.py)
at robot.utils.importer$py.import_$32(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/utils/importer.py:274)
at robot.utils.importer$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/utils/importer.py)
at robot.utils.importer$py._import_class_or_module$5(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/utils/importer.py:77)
at robot.utils.importer$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/utils/importer.py)
at robot.utils.importer$py.import_class_or_module$4(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/utils/importer.py:74)
at robot.utils.importer$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/utils/importer.py)
at robot.libdocpkg.robotbuilder$py.build$2(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/libdocpkg/robotbuilder.py:40)
at robot.libdocpkg.robotbuilder$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/libdocpkg/robotbuilder.py)
at robot.libdocpkg$py.LibraryDocumentation$1(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/libdocpkg/__init__.py:47)
at robot.libdocpkg$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/libdocpkg/__init__.py)
at robot.libdoc$py.main$4(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/libdoc.py:163)
at robot.libdoc$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/libdoc.py)
at robot.utils.application$py._execute$10(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/utils/application.py:94)
at robot.utils.application$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/utils/application.py)
at robot.utils.application$py.execute$9(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/utils/application.py:79)
at robot.utils.application$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/utils/application.py)
at robot.libdoc$py.libdoc$9(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/libdoc.py:223)
at robot.libdoc$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages/robot/libdoc.py)
at red_libraries$py._create_libdoc_with_stdout_redirect$5(/private/var/folders/dv/nnfc_k29377bv7s34kng7qgh0000gn/T/RobotTempDir8808901746972554502/red_libraries.py:83)
at red_libraries$py.call_function(/private/var/folders/dv/nnfc_k29377bv7s34kng7qgh0000gn/T/RobotTempDir8808901746972554502/red_libraries.py)
at red_libraries$py.create_libdoc$4(/private/var/folders/dv/nnfc_k29377bv7s34kng7qgh0000gn/T/RobotTempDir8808901746972554502/red_libraries.py:66)
at red_libraries$py.call_function(/private/var/folders/dv/nnfc_k29377bv7s34kng7qgh0000gn/T/RobotTempDir8808901746972554502/red_libraries.py)
at SimpleXMLRPCServer$py._dispatch$15(/usr/local/Cellar/jython/2.7.1/libexec/Lib/SimpleXMLRPCServer.py:422)
at SimpleXMLRPCServer$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/SimpleXMLRPCServer.py)
at SimpleXMLRPCServer$py._marshaled_dispatch$10(/usr/local/Cellar/jython/2.7.1/libexec/Lib/SimpleXMLRPCServer.py:276)
at SimpleXMLRPCServer$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/SimpleXMLRPCServer.py)
at SimpleXMLRPCServer$py.do_POST$19(/usr/local/Cellar/jython/2.7.1/libexec/Lib/SimpleXMLRPCServer.py:535)
at SimpleXMLRPCServer$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/SimpleXMLRPCServer.py)
at BaseHTTPServer$py.handle_one_request$7(/usr/local/Cellar/jython/2.7.1/libexec/Lib/BaseHTTPServer.py:345)
at BaseHTTPServer$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/BaseHTTPServer.py)
at BaseHTTPServer$py.handle$8(/usr/local/Cellar/jython/2.7.1/libexec/Lib/BaseHTTPServer.py:352)
at BaseHTTPServer$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/BaseHTTPServer.py)
at SocketServer$py.__init__$47(/usr/local/Cellar/jython/2.7.1/libexec/Lib/SocketServer.py:659)
at SocketServer$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/SocketServer.py)
at SocketServer$py.finish_request$13(/usr/local/Cellar/jython/2.7.1/libexec/Lib/SocketServer.py:334)
at SocketServer$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/SocketServer.py)
at SocketServer$py.process_request$11(/usr/local/Cellar/jython/2.7.1/libexec/Lib/SocketServer.py:322)
at SocketServer$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/SocketServer.py)
at SocketServer$py._handle_request_noblock$8(/usr/local/Cellar/jython/2.7.1/libexec/Lib/SocketServer.py:298)
at SocketServer$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/SocketServer.py)
at SocketServer$py.serve_forever$5(/usr/local/Cellar/jython/2.7.1/libexec/Lib/SocketServer.py:241)
at SocketServer$py.call_function(/usr/local/Cellar/jython/2.7.1/libexec/Lib/SocketServer.py)
PYTHONPATH:
/Users/roja/Automation/Jars-For-KTOC/TRBJars1.jar
/private/var/folders/dv/nnfc_k29377bv7s34kng7qgh0000gn/T/RobotTempDir8808901746972554502
/usr/local/Cellar/jython/2.7.1/libexec/Lib
__classpath__
__pyclasspath__/
/usr/local/Cellar/jython/2.7.1/libexec/Lib/site-packages
CLASSPATH:
../../../../usr/local/Cellar/jython/2.7.1/libexec/jython.jar
.
Try --help for usage information.
Xls_Reader.java 文件中的以下代码
/**
*
*/
package com.KTOC.TRB.testautomation.Utilities;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Hashtable;
public class Xls_Reader {
public String path;
public FileInputStream fis = null;
private static XSSFWorkbook workbook = null;
private static XSSFSheet sheet = null;
public XSSFRow row = null;
private XSSFCell cell = null;
public static Xls_Reader xlsx;
public static final String ROBOT_LIBRARY_SCOPE = "GLOBAL";
Xls_Reader (String path) {
ClassLoader classloader = getClass().getClassLoader();
try {
InputStream fis = classloader.getResourceAsStream(path);
workbook = new XSSFWorkbook(fis);
sheet = workbook.getSheetAt(0);
fis.close();
} catch (Exception e) {
}
}
String getCellData(String sheetnam, int colnum, int rownum) {
try {
if (rownum <= 0) {
return "";
}
int index = workbook.getSheetIndex(sheetnam);
if (index == -1) {
return "";
}
sheet = workbook.getSheetAt(index);
row = sheet.getRow(rownum - 1);
if (row == null) {
return "";
}
cell = row.getCell(colnum);
if (cell == null) {
return "";
}
} catch (Exception ignored) {
}
return cell.toString();
}
// returns the row count in a sheet
public int getRowCount(String sheetName) {
int index = workbook.getSheetIndex(sheetName);
if (index == -1) {
return 0;
} else {
sheet = workbook.getSheetAt(index);
return sheet.getLastRowNum() + 1;
}
}
// returns number of columns in a sheet
public int getColumnCount(String sheetName) {
sheet = workbook.getSheet(sheetName);
row = sheet.getRow(0);
if (row == null) {
return -1;
}
return row.getLastCellNum();
}
public static String getData(String SheetName, String TestCase, String parameter)
{
String parametervalue = null;
Xls_Reader xlsx = new Xls_Reader("../Users/roja/eclipse-workspace/KTOC_TestMethods/src/testautomation/TestData/KTOCData.xlsx");
Hashtable<String, String> hTable = getDatafromXlsx(TestCase, xlsx, SheetName);
parametervalue = (String) hTable.get(parameter);
return parametervalue;
}
public static Hashtable<String, String> getDatafromXlsx(String testcaseName, Xls_Reader xls, String sheetname)
{
int testcaseStartrow = 1;
while (!xls.getCellData(sheetname, 0, testcaseStartrow).equals(testcaseName))
{
testcaseStartrow++;
}
int testDataStartrownum = testcaseStartrow + 2;
int rows = 0;
while (!xls.getCellData(sheetname, 0, testDataStartrownum + rows).equals(""))
{
rows++;
}
int colStartRownum = testcaseStartrow + 1;
int cols = 0;
while (!xls.getCellData(sheetname, cols, colStartRownum).equals(""))
{
cols++;
}
Hashtable<String, String> table = null;
for (int rNum = testDataStartrownum; rNum < testDataStartrownum + rows; rNum++) {
table = new Hashtable<String, String>();
for (int cNum = 0; cNum < cols; cNum++) {
String key = xls.getCellData(sheetname, cNum, colStartRownum);
String value = xls.getCellData(sheetname, cNum, rNum);
table.put(key, value);
}
}
return table;
}
}
【问题讨论】:
-
就上下文而言,库规范文件仅由 RED 用于 RED 中的自动完成和文档功能。这不会影响运行 Robot Framework 脚本时的功能。除了这个功能性错误之外,还有技术错误吗?如果您有一个简单的 java 类将其作为 minimal reproducible example 触发此问题,那将有所帮助。
-
感谢@A.Kootstra 的回复。
-
我能够完美地导出到 jar 中,没有任何错误。从功能上看,这似乎不是技术问题。但是在构建它时,似乎存在技术问题。我也跟着这个,在机器人引用库下的项目资源管理器中,右键单击类名并单击重新加载菜单。重新加载时,收到错误。我用这个错误更新了问题。
标签: robotframework