Quantcast
Channel: Pochampalli IT Labs
Viewing all articles
Browse latest Browse all 261

How to run power shell script file in selenium cucumber AfterAll hook using JVM shutdown method

$
0
0

@AfterAll(order =1)// Cucumber AfterAll hook with order 2publicstaticvoidputFile()throws JSchException, SftpException, IOException, InterruptedException {
		Log.info("AfterAll - with order=1");

		InetAddress localhost = InetAddress.getLocalHost();
		Log.info("System IP Address : "+(localhost.getHostAddress()).trim());if(localhost.getHostAddress().trim().equals("11.111.44.77")){
			Runtime.getRuntime().addShutdownHook(new Thread(new Runnable(){@Overridepublicvoidrun(){try{// Path to your PowerShell script
						String scriptPath ="C:\\APIAutomation\\qa-api-rc-cucumber-restassured.ps1";// Command to run PowerShell with execution policy bypass and script execution
						String[] command ={"powershell","-ExecutionPolicy","Bypass","-File", scriptPath };// Create process builder
						ProcessBuilder pb =new ProcessBuilder(command);// Start the process
						Process process = pb.start();// Read the output
						BufferedReader reader =new BufferedReader(new InputStreamReader(process.getInputStream()));
						String line;while((line = reader.readLine())!=null){
							System.out.println(line);}// Wait for the script to finishint exitCode = process.waitFor();
						System.out.println("Script execution finished with exit code: "+ exitCode);}catch(IOException | InterruptedException e){
						e.printStackTrace();}}}));
			System.out.println("Application Terminating ...");}else{
			System.out.println("Since this is not the lab server skipping sending email from linux server");}}
Hi

Viewing all articles
Browse latest Browse all 261

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>