我正在尝试访问Worker类中的outTextScreen文本区域,但出现错误。
这里的上下文是fxmlcontroller类中的executeWSButton方法将调用create worker方法,该方法将使用InvokeTestng类创建一个testng套件。该套件将具有worker类,我想访问workerMain方法中的fxml textarea(outTextScreen)。 >
我尝试在workerMain方法中创建fxmlcontoller类的对象,但出现错误。您能否让我知道如何访问worker类中的fxml元素
FXMLController
@SuppressWarnings({ "rawtypes", "deprecation" })
public class FXMLController implements Initializable {
Task copyWorker;
@FXML
Text textOutput;
@FXML
TextArea outputTextScreen;
// execute button event
@FXML
public void executeWSButton(ActionEvent event) {
outputTextScreen.appendText(newLine + "Webservice Execution for Process: Started" + newLine);
executeWS.setDisable(true);
copyWorker = createWorker();
}
public Task createWorker() {
return new Task() {
@Override
protected Object call() throws Exception {
outputTextScreen.appendText(newLine + "Inside create worker" + newLine);
Invoke_TestNG_Classes ws = new Invoke_TestNG_Classes();
String output = ws.iterateThroughTestCases(inputfile_fp, GIfile_fp, testModule,excelPath);
return true;
}
};
}
}
/*===============================================================================================================================
调用TestNG类
@SuppressWarnings("unused")
public class Invoke_TestNG_Classes {
static Map<Integer, String> col1Data = new LinkedHashMap<Integer, String>();
static Map<Integer, String> col2Data = new LinkedHashMap<Integer, String>();
static Map<String, String> finalKeyValuePair = new LinkedHashMap<String, String>();
static List<String> testCaseList = new ArrayList<String>();
//static String excelPath = "C:\\Automation_OCTS\\Data\\TestCaseExecution.xlsx";
@SuppressWarnings({ "deprecation", "null" })
public Map<String,String> readExcel(String excelPath) throws IOException {
// Write a code to read test cases from excel and pass the arraylist to
// testcase.add()
Integer columnNo = null;
String columnWanted;
FileInputStream fileInputStream = new FileInputStream(new File(
excelPath));
@SuppressWarnings("resource")
XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream);
XSSFSheet sheet = workbook.getSheetAt(0);
Row firstRow = sheet.getRow(0);
for (Cell cell : firstRow) {
columnWanted = "Test Case Name";
if (cell.getStringCellValue().equals(columnWanted)) {
columnNo = cell.getColumnIndex();
}
}
if (columnNo != null) {
for (Row row : sheet) {
Cell c = row.getCell(columnNo);
if (c != null || c.getCellType() == Cell.CELL_TYPE_BLANK) {
col1Data.put(row.getRowNum(), c.toString());
}
}
}
for (int rowNumber = 0; rowNumber <= sheet.getLastRowNum(); rowNumber++) {
XSSFRow row = sheet.getRow(rowNumber);
for (int columnNumber = 0; columnNumber <= row.getLastCellNum(); columnNumber++) {
XSSFCell cell = row.getCell(columnNumber);
if (cell != null) {
col2Data.put(row.getRowNum(), cell.toString());
}
}
}
for (Entry<Integer, String> col1map : col1Data.entrySet())
for (Entry<Integer, String> col2map : col2Data.entrySet()) {
if (col1map.getKey() != 0 && col2map.getKey() != 0
&& col1map.getKey() == col2map.getKey()) {
finalKeyValuePair.put(col1map.getValue(),
col2map.getValue());
}
}
/*System.out.println("Excel Values mapped :");
for (Entry<String, String> map : finalKeyValuePair.entrySet()) {
System.out.println(map);
}*/
return finalKeyValuePair;
}
@Test
public String iterateThroughTestCases(String testFile, String InterfaceFIle, String testModule,String excelPath) throws IOException {
finalKeyValuePair= readExcel(excelPath);
Iterator<Entry<String, String>> iterator = finalKeyValuePair.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, String> pair = iterator.next();
if(pair.getValue().equals("Y"))
{
testCaseList.add(pair.getKey());
}
}
if(testCaseList.size()==0)
{
return "Mark atleast one test case with Flag as Y";
}
// Creating a new Suite
XmlSuite suite = new XmlSuite();
for (Integer i = 0; i < testCaseList.size(); i++) {
// Creating a new Test
XmlTest test = new XmlTest(suite);
// Set Test name
test.setName("test-number-" + i);
// New list for the parameters
Map<String, String> testParams = new HashMap<String, String>();
// Add parameter to the list
testParams.put("testFile", testFile);
testParams.put("InterfaceFile", InterfaceFIle);
// Add parameters to test
test.setParameters(testParams);
// New list for the classes
List<XmlClass> classes = new ArrayList<XmlClass>();
// Putting the classes to the list
classes.add(new XmlClass(testModule+testCaseList.get(i)));
// Add classes to test
test.setClasses(classes);
}
// New list for the Suites
List<XmlSuite> suites = new ArrayList<XmlSuite>();
// Add suite to the list
suites.add(suite);
// Creating the xml
TestListenerAdapter tla = new TestListenerAdapter();
TestNG tng = new TestNG();
tng.setXmlSuites(suites);
System.out.println(suite.toXml());
// tng.addListener(tla);
tng.run();
return "Completed";
}
}
/*==============================================================================
工人阶级
@SuppressWarnings("unused")
public class Worker extends ReporterBaseTest {
@SuppressWarnings("restriction")
@Parameters({ "testFile", "InterfaceFile" })
@Test
public void workerMain(String inputfile_fp,String file_fp) throws Exception {
//Error
outputTextScreen.appendText(newLine + "Worker Webservice Execution for Process: Started" + newLine);
}
}`enter code here`
强文本