【发布时间】:2016-08-13 17:31:52
【问题描述】:
我是 Java 新手。
我正在使用 Selenium。我有three 类ATSmoke 这是主要类。我在 Excel 工作表中的所有方法名称都在其他两个类Profile 和Schedule 中。现在我使用POI library 来获取单元格值(即方法名称)。
这里我卡住了,如何在另一个类 Profile 中调用这些方法(edit_contact_info)。如果他们在同一个班级。我可以使用相同的类名来引用。但不能为其他课程做。
另外,还有一个名为 ATTestDriver 的类,我拥有所有实用方法,例如选择 webdriver、浏览器等。
public class ATSmoke {
public static void main(String[] args){
Profile profileDriver = new Profile(Browsers.CHROME);
XSSFWorkbook srcBook = null;
try {
srcBook = new XSSFWorkbook("./TestData/Testcase_data_v1.xlsx");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
XSSFSheet sourceSheet = srcBook.getSheet("Testcases");
int rowCount = sourceSheet.getLastRowNum();
for (int i=1; i<=rowCount; i++){
int rownum=i;
XSSFRow testcaserow=sourceSheet.getRow(rownum);
XSSFCell testcase_Name= testcaserow.getCell(1);
String flagState=testcaserow.getCell(2).getStringCellValue();
if (flagState.equals("yes")) {
if (testcase_Name != null) {
try {
Method myMethod = ATSmoke.class.getMethod(testcase_Name.getStringCellValue());
myMethod.invoke(new ATSmoke());
} catch (NoSuchMethodException | SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("");
}
}
}
try {
srcBook.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public class Profile extends ATTestDriver {
public Profile(Browsers browser) {
super(browser);
}
public void edit_contact_info() {
WebElement pageopened =this.waitForElement(By.cssSelector(".qualifications p b b"));
System.out.println("you have " +pageopened.getText());
driver.findElement(By.cssSelector("contact-information button")).click();
}
}
【问题讨论】:
-
profileDriver.edit_contact_info()?
标签: java excel selenium methods invoke