I have scripted a Selenium automation testcase. I have generated the testng.xml file which should be executed on the linux terminal at a particular time of my need. Say I want to schdule to execute the testng.xml file on terminal at 11pm everyday.

  • 1
    Why do you need terminal? If you need environment vars you can set them in script run by cron – Romeo Ninov Nov 16 '18 at 10:05
  • Because I want to schedule the execution to run at a specific time. In order to do that I thought executing/running the script on the terminal would make it easier to schedule. – Kasturi Rajamanikkam Nov 16 '18 at 11:03
  • I do not know easier scheduling system than cron. Please provide the script and schedule times to be able to help you. – Romeo Ninov Nov 16 '18 at 11:17
  • @RomeoNinov I have scripted and generated the test script into a testng.xml file. So that I could execute it on the terminal. The location of the testng.xml file be like: /home/kasturi/workspace/app. What I do in order to run the script on the terminal is I first do to the particular directory via the command: cd /home/dananja/workspace/simsapp. Then I put this command to execute the script: java -cp "./lib/*:./bin" org.testng.TestNG testng.xml. I want to schedule that manual activity. I hope you get my problem. – Kasturi Rajamanikkam Nov 19 '18 at 7:00

Authomation of the task can be done on this way: Create in your home directory a script (with name script.sh for example) which contain:

#do not forget to set propper path to java executable
source /home/dananja/.bash_profile
cd /home/dananja/workspace/simsapp
$JAVA -cp "./lib/*:./bin" org.testng.TestNG testng.xml

And in cron (via command crontab -e) add record like this:

0 23 * * * /home/dananja/script.sh

To make your script executable do not forget to exec (once)

chmod +x /home/dananja/script.sh
  • Thank you @Romeo I tried as you suggested. But it didn't work. I want to automate the process of opening the terminal and go to the particular directory and execute the script command... – Kasturi Rajamanikkam Nov 19 '18 at 7:46
  • The execution of the selenium script should run in the terminal. – Kasturi Rajamanikkam Nov 19 '18 at 7:48
  • Please provide the logs from cron log when you exec the script. And did you set execution flag on the script? – Romeo Ninov Nov 19 '18 at 7:58
  • I didn't do any such thing. I mean I'm not so much into Linux. I'm not aware of cron log or what do you mean by execution flag? Please assist – Kasturi Rajamanikkam Nov 19 '18 at 8:18
  • The usual place for cron log is file /var/log/cron. And maybe you will need to be root user to see it. – Romeo Ninov Nov 19 '18 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.