Red.xml-使用“添加Java库”按钮上传Java jar文件时出现此错误。
未为“ Library.class.name”生成库规范文件 库
尝试了以下步骤,
注意:从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;
}
}
答案 0 :(得分:1)
示例Robot Framework Java库取自Robot Framework user guide。当导出为常规jar文件并导入RED项目文件时,将生成关键字LibSpec文件,并在项目浏览器概述中显示关键字。
当RED初始化类以读取方法和文档并从中生成LibSpec时,就会出现问题。这需要在没有有效的Robot Framework上下文的情况下单独初始化该类。如果您的类初始化时期望某些上下文处于活动状态,则这将在生成LibSpec时引发错误,但在运行测试时效果很好。
/**
*
*/
package com.mycompany;
/**
* @author anne
*
*/
public class ExampleLibrary {
public static final String ROBOT_LIBRARY_SCOPE = "GLOBAL";
private int counter = 0;
public void count() {
counter += 1;
System.out.println(counter);
}
public void clearCounter() {
counter = 0;
}
}
答案 1 :(得分:0)