实际上,我正在尝试运行 selenium 框架来进行 Web 应用程序测试。 我能够使用 Excel 工作表数据作为输入来运行该框架。当我尝试使用不同的输入运行该框架时,我的框架应该在本地系统中同时使用不同的输入运行。我认为这可以在线程池执行器中完成。 我可以为两组输入启动两个线程。但是当第二个线程启动时,第一个线程就会死亡。但是在使用单输入运行时,它运行良好。我不知道我的代码中缺少什么。我已经给出了下面的代码, 请各位 friend 看看,
Driverscript.java
public static void main (String[] args) throws ReflectiveOperationException, Exception {
String configPath =args[0];
DriverScript Test = new DriverScript(configPath);
//Test.start(configPath);
String mapFile=CONFIG.getProperty("Application");
Xls_Reader ApplicationXLS=new Xls_Reader(mapFile);
int rowCount=ApplicationXLS.getRowCount(Constants.TEST_APP_SHEET);
ExecutorService executor =Executors.newFixedThreadPool(rowCount);
for(int CurrentApplicationID=2;CurrentApplicationID<=ApplicationXLS.getRowCount(Constants.TEST_APP_SHEET);CurrentApplicationID++){
if(ApplicationXLS.getCellData(Constants.TEST_APP_SHEET, Constants.TEST_APP_RUNMODE,CurrentApplicationID).equalsIgnoreCase("Permitted")){
SuitePath=ApplicationXLS.getCellData(Constants.TEST_APP_SHEET, Constants.TEST_APP_SUITEPATH,CurrentApplicationID);
ObjectRepo=ApplicationXLS.getCellData(Constants.TEST_APP_SHEET, Constants.TEST_APP_OBJECT_REPOSITORY,CurrentApplicationID);
new ObjectRepLocator(ObjectRepo);
SuiteXLS = new Xls_Reader(SuitePath);
CurrentSuiteSheet=ApplicationXLS.getCellData(Constants.TEST_APP_SHEET, Constants.TEST_APP_ID, CurrentApplicationID);
Runnable worker=new ThreadScheduler(SuiteXLS,CurrentSuiteSheet);
Thread.currentThread().join(3000);
executor.execute(worker);
}
}
executor.shutdown();
if(executor.isTerminated())
new ReportUtil(configPath,SuitePath);
}
public static void start(Xls_Reader SuiteXLS,String CurrentSuiteSheet) throws ReflectiveOperationException, IllegalArgumentException, Exception {
<<----content of the Start() function---->>
}
ThreadScheduler.java
public class ThreadScheduler implements Runnable {
public static Xls_Reader SuiteXLS;
public static String currentSuiteSheet;
public static String currentTestSuitePath;
ThreadScheduler(Xls_Reader SuiteXLS, String CurrentSuiteSheet){
this.SuiteXLS=SuiteXLS;
this.currentSuiteSheet=CurrentSuiteSheet;
// this.currentTestSuitePath=CurrentTestSuitePath;
}
@Override
public void run(){
try{
System.out.println(Thread.currentThread().getName());
System.out.println(Thread.currentThread().getState());
System.out.println(SuiteXLS);
System.out.println(currentSuiteSheet);
DriverScript.start(SuiteXLS,currentSuiteSheet);
System.out.println("End of "+ Thread.currentThread().getName());
}
catch(Exception e){
e.printStackTrace();
}
}
我正在使用 Eclispe juno。该框架用于 Selenium 自动化。 提前感谢 friend 们...
最佳答案
您正在调用“executor.shutdown();”明确地,这就是您的线程死亡的原因,否则它会在线程池中等待任务。就您的问题而言,您需要一种重复任务,可以通过使用诸如quartz调度之类的东西来实现,其中可以将任务配置为以独立的重复间隔并行运行。
关于java - 如何在java中使用线程池执行器同时运行单个java应用程序两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20285281/