【问题标题】:Returning control to Selenium test execution after completing autoIt execution完成 autoIt 执行后将控制权返回给 Selenium 测试执行
【发布时间】:2018-12-27 07:20:05
【问题描述】:

我正在编写一个 selenium 自动化测试脚本,其中涉及将我的图片作为个人资料图片上传到门户中。该过程成功执行,直到我调用 runAutoit() 函数,该函数将图片加载到 Windows 资源管理器框中并单击打开,但不考虑此点之后的 3 行代码。总结一下我的担忧 - “在runAutoIt() 方法之后,控件不会继续执行硒。​​

这是我调用 runAutoIT() 函数的 selenium 代码


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);
    }

    }

我已经尝试使用窗口焦点方法并在 try catch 块中插入未执行的代码,但没有成功。程序中runAutoit()函数后的那行代码没有执行。

我希望测试执行在 runAutoit() 函数之后单击上传按钮,但实际上在成功执行 runAutoit() 方法后执行停止。控制台中没有错误信息。

【问题讨论】:

    标签: java selenium selenium-webdriver focus autoit


    【解决方案1】:

    就像您在两个 AutoIT 方法之间引入硬编码 Thread.sleep(1500); 的方式:

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

    runAutoIT(); 之后诱导一些 wait 以使进程结束,然后尝试将焦点保留到 Selenium,如下所示:

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

    你可以在Return control to Selenium after executing an AutoIt script找到类似的讨论

    【讨论】:

      【解决方案2】:

      虽然我晚了几年,但以下内容可以帮助您或其他人:

      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();
          //
      }
      

      【讨论】:

        【解决方案3】:
        ((JavascriptExecutor) driver).executeScript("window.focus();");
        

        【讨论】:

        • 你能解释一下你的答案吗?这段代码在做什么?
        猜你喜欢
        • 1970-01-01
        • 2016-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多