Wednesday, 8 June 2016

Scheduling the execution of selenium automation test scripts in Mac Using Ant, Mac Automator tool and Applescript.

Assumptions: ant is installed and selenium automation Frame work is configured for ant build.xml to run the script execution

Follow the tips given below for achieving the daily selenium automatic script execution on mac.

Creating Mac Calendar Event:


1. Create a Calendar event in Mac Calendar and give any name eg: 'QAAutoTask'.
2. Set the start and end time of the Event based on the required daily script execution time. eg: 7:00 PM
3. Select the option 'Every Day' to make sure script runs daily.
4.Click on apply to save the event.


Creating Automator Task:


1.Open mac Automator Tool from Applications.
2.Select Calender in the 'Choose a type for your document'
3.Click on choose button.



4.Enter 'apple' in the search field for Action.
5.Select 'AppleScript' from the result and drag it to the RHS window pane.


6.Enter the apple script to navigate to the automation framework with ant build.xml and for running the ant build.
eg:
on run {input, parameters}
tell application "Terminal"
activate
do script "cd  '/Path_to_the_Project_having_ant_build.xml_file/ProjectName' ;/Applications/apache-ant-1.9.6/bin/ant -buildfile build.xml"
end tell
return input

end run

7.Click on Run button and check applescript is able to trigger the ant build.xml and start the script execution process.
8.Save the file in any location eg: Desktop (Command +Click on default name to Save the file in desired location) by giving the some name.




Browsing the same file from calendar event:


1.Now comeback to Calendar and edit the same previous calendar event by clicking Edit->Edit Event
2.Click on Alert and select custom and select open file and browse to the Automator AppleScript file saved earlier.
Note: you can edit the start time of the calendar event by clicking on the starts time and entering the new time



Now when the Calendar event time reaches the Event start time then it triggers the script and script triggers the Ant build.xml and start the Automation Script Execution.