I have a test case and I want to use Quartz to running with the schedule. But I don't know how to prepare data before Quartz start. I mean I want to call function prepareData() after set up Quartz start call function clickButton(). You can see in my code

This is my class Test.class

public void prepareData(){
        System.setProperty("webdriver.chrome.driver", ResourceHelper.getResourcePath("src/main/resources/drivers/linux/chromedriver"));
        WebDriver driver2 = new ChromeDriver();
        driver2.get("https://google.com");
}

public void clickButton(){
         driver2.findElement(btnSubmit).click();
}

@Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.out.println("Run my Job: " + new Date());

        clickButton();

    }

And class Quartz


public class Demo{

    public static void main(String[] args) throws SchedulerException{

        Trigger trigger = TriggerBuilder.newTrigger().withIdentity("triggerName", "group1")
                .withSchedule(CronScheduleBuilder.cronSchedule("0/10 21 11 ? * * *")).build();

        JobDetail job = JobBuilder.newJob(Test.class)
                .withIdentity("jobName", "group1").build();
        Scheduler scheduler = new StdSchedulerFactory().getScheduler();
        scheduler.start();
        scheduler.scheduleJob(job, trigger);
    }
}

0 Answers