如何將Sikuli指令碼整合到Selenium中?


我們可以將Sikuli指令碼整合到Selenium webdriver中。Sikuli是一個開源的自動化工具。它具有捕獲元素影像以及對其執行操作的功能。

Sikuli的一些優點包括:

  • 可以自動化桌面或Windows應用程式。

  • 可用於Flash測試。

  • 可用於移動、Mac和Linux等平臺。

  • 它基於影像識別技術。

  • 可以輕鬆地與Selenium整合。

要將Sikuli與Selenium整合,請按照以下步驟操作:導航到連結 - https://launchpad.net/sikuli/+download.

點選jar檔案下載它(可用於Java環境)並將其儲存在某個位置。

將jar檔案新增到Eclipse IDE中的Java專案中。右鍵點選專案並選擇**屬性**。然後點選**Java構建路徑**。轉到**Java構建路徑**選項卡。點選**庫**。然後點選**新增外部JARs**。瀏覽並新增我們下載的Sikuli jar檔案。最後,點選**應用並關閉**。

使用**Sikuli**捕獲我們將輸入**Selenium**的編輯框的影像,並將其儲存在某個位置。

示例

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Pattern;
import org.sikuli.script.Screen;
public class SikuliIntegrate{
   public static void main(String[] args) {
      System.setProperty("webdriver.chrome.driver",       "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      driver.get("https://tutorialspoint.tw/index.htm");
      // Screen class to access Sikuli methods
      Screen s = new Screen();
      //object of Pattern to specify image path
      Pattern e = new Pattern("C:\Users\ghs6kor\Image.png");
      //add wait time
      s.wait(e, 5);
      //enter text and click
      s.type(e, "Selenium");
      s.click(e);
   }
}

輸出

更新於: 2021年2月1日

2K+ 次檢視

開啟您的職業生涯

透過完成課程獲得認證

開始學習
廣告