0

I am writing a selenium automation test script that involves uploading my picture as the profile picture in a portal. The process executes successfully until I call the runAutoit() function that loads the picture in the windows explorer box and clicks on open but does not consider the 3 lines of code after this point. To summarize my concern - "The control does not continue with the selenium execution after the runAutoIt() method.

This is my selenium code in which i have called the runAutoIT() function


package com.cstudymaven.testscript;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;

import com.cstudymaven.utilities.ReadExcel;
import com.cstudymaven.pompages.EditProfile;
import com.cstudymaven.pompages.SignInPage;
import com.cstudymaven.utilities.BaseTest;

public class TestScript extends BaseTest
{
SignInPage signin = null;
EditProfile edprf=null;

@Test
public void signUp() 
{

    JavascriptExecutor js = (JavascriptExecutor) driver;
        String[][] credentials = ReadExcel.getData(filePath, "User_Login");
    try {

        for (int i = 1; i < credentials.length; i++) {
            String email = credentials[0];
            String password = credentials[1];
            signin = new SignInPage(driver);
            signin.clickonLogin();
            Thread.sleep(1500);
            signin.enterEmail(email);
            Thread.sleep(1500);
            signin.enterPassword(password);
            signin.clicktoStart();
            edprf=new EditProfile(driver);
            wait = new WebDriverWait(driver, 10);
            Thread.sleep(1500);
            edprf.editprofile();
            Thread.sleep(1500);
            edprf.gotoprofile();
            Thread.sleep(1500);
            edprf.editlogo();
            wait = new WebDriverWait(driver, 10);
            Thread.sleep(2700);
            edprf.camera();
            Thread.sleep(2500);
            edprf.cfile();
            Thread.sleep(1500);
            runAutoIT();           

((JavascriptExecutor) driver).executeScript("window.focus();");
 js.executeScript("window.scrollBy(0,150)");  
  WebElement upld 
  =driver.findElement(By.xpath("//button[@type='submit']"));
   upld.click();

   }
   }

   catch (Exception e) 
             {
   e.printStackTrace();
   try 
   {

   } 
   catch (Exception e1) 
   {

   }

   }

   }               


    public void runAutoIT() throws Exception
    {
    String strFilePath="C:\\Users\\LOBO\\1Amanfred.jpg";    
    String strPath="C:\\Users\\LOBO\\eclipse- 
    workspace\\CaseStudyMaven\\InputData\\cstudymaven.exe";
    String strParameter=strPath+" "+strFilePath;
    Runtime.getRuntime().exec(strParameter);
    }

    }

I have already tried using window focus method and inserting the code that is not executing in try catch block, but no success. The line of code in the program after the runAutoit() function does not execute.

I expect the test execution to click on upload button after the runAutoit() function, but actually the execution stops after successfully executing the runAutoit() method. There is no error message in the console.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

3 Answers3

0

Just like the way you induced hardcoded Thread.sleep(1500); between two AutoIT methods:

edprf.cfile();
Thread.sleep(1500);
runAutoIT();

Induce some wait after runAutoIT(); for the process to end and then try to retain the focus to Selenium as follows:

runAutoIT(); 
Thread.sleep(3500);
((JavascriptExecutor) driver).executeScript("window.focus();");

You can find a similar discussion in Return control to Selenium after executing an AutoIt script

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Although I am few years late, the following help you or others:

public void runAutoIT() throws Exception
    {
    String strFilePath="C:\\Users\\LOBO\\1Amanfred.jpg";    
    String strPath="C:\\Users\\LOBO\\eclipse- 
    workspace\\CaseStudyMaven\\InputData\\cstudymaven.exe";
    String strParameter=strPath+" "+strFilePath;
    // pay attention to this part
    Process p = Runtime.getRuntime().exec(strParameter);
    p.waitFor();
    //
}
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Asjad Azeez
  • 53
  • 13
-1
((JavascriptExecutor) driver).executeScript("window.focus();");
Jin Lee
  • 3,194
  • 12
  • 46
  • 86