2017-08-08 354 views
-1

我試圖在Mac上自動化桌面應用程序。我寫了下面的代碼:Mac OS上的桌面應用程序自動化

import java.net.MalformedURLException; 
import java.net.URL; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.remote.DesiredCapabilities; 
import org.openqa.selenium.remote.RemoteWebDriver; 
import org.testng.annotations.Test; 

public class createTemplate { 

    @Test 
    public void newTemplate() throws InterruptedException, MalformedURLException { 

     String fileMenu = "/AXApplication[@AXTitle='AppiumForMac']/AXMenuBar[0]/AXMenuBarItem[@AXTitle='File']"; 
     String createNewTemplate = "/AXApplication[@AXTitle='OpsGenie']/AXMenuBar[0]/AXMenuBarItem[@AXTitle='File']/AXMenu[0]/AXMenuItem[@AXTitle='Create New Template']"; 
     String templateName = "/AXApplication[@AXTitle='OpsGenie']/AXWindow[@AXIdentifier='_NS:10' and @AXSubrole='AXStandardWindow']/AXSheet[0]/AXTextField[@AXIdentifier='_NS:114']"; 
     String supportedRoles = "/AXApplication[@AXTitle='OpsGenie']/AXWindow[@AXIdentifier='_NS:10' and @AXSubrole='AXStandardWindow']/AXSheet[0]/AXScrollArea[@AXIdentifier='_NS:181']/AXTable[@AXIdentifier='_NS:185']/AXRow[@AXSubrole='AXTableRow']/AXCell[0]/AXButton[@AXIdentifier='_NS:49']"; 
     String numberOfPodes = "/AXApplication[@AXTitle='OpsGenie']/AXWindow[@AXIdentifier='_NS:10' and @AXSubrole='AXStandardWindow']/AXSheet[0]/AXStaticText[@AXIdentifier='_NS:85']"; 
     String VRCast = "/AXApplication[@AXTitle='OpsGenie']/AXWindow[@AXIdentifier='_NS:10' and @AXSubrole='AXStandardWindow']/AXSheet[0]/AXStaticText[@AXIdentifier='_NS:17']"; 
     String doneButton = "/AXApplication[@AXTitle='OpsGenie']/AXWindow[@AXIdentifier='_NS:10' and @AXSubrole='AXStandardWindow']/AXSheet[0]/AXButton[@AXTitle='Done' and @AXIdentifier='_NS:283']"; 
     DesiredCapabilities capabilities = new DesiredCapabilities(); 
     capabilities.setCapability("platform","Mac"); 
     WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4622/wd/hub"),capabilities); 
     driver.get("OpsGenie"); 
     Thread.sleep(2000); 
     driver.findElement(By.xpath(fileMenu)).click(); 
     driver.findElement(By.xpath(createNewTemplate)).click(); 
     driver.findElement(By.xpath(templateName)).sendKeys("New Template"); 
     driver.findElement(By.xpath(supportedRoles)).click(); 
     driver.findElement(By.xpath(numberOfPodes)).sendKeys("1"); 
     driver.findElement(By.xpath(VRCast)).sendKeys("Yes"); 
     driver.findElement(By.xpath(doneButton)).click(); 

    } 

} 

而且我收到以下錯誤:

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. 
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' 
System info: host: 'TACH0029', ip: '192.168.1.8', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144' 

我不知道是什麼問題。任何人都可以幫忙嗎?

+1

硒是一個開發工具在瀏覽器中測試網站。據我所知,它不能控制任意的應用程序。 – cello

+0

藉助AppiumFor Mac應用程序,Selenium可用於Mac上的桌面應用程序的自動化。請參閱鏈接https://medium.com/@rajuayyampillai/how-to-automate-any-desktop-application-d7b4615d6f1f – Amrutha

回答

0

Selenium僅用於自動化Web應用程序。

如果您需要自動化的桌面應用程序,你可以嘗試以下任何框架: -

  • QTP
  • Sikuli
  • 自動IT

QTP介紹: - (付費應用程序)

QTP代表惠普(HP)的QuickTest Professional產品。該工具可幫助測試人員在腳本開發完成後無縫監控自動功能測試。 HP QTP使用Visual Basic腳本(VBScript)來自動化應用程序。 https://www.guru99.com/quick-test-professional-qtp-tutorial-1.html

Sikuli: - (免費申請)

Sikuli自動化任何你在屏幕上看到的。它使用圖像識別來識別和控制GUI組件。當不能輕鬆訪問GUI的內部或源代碼時非常有用。

http://www.softwaretestinghelp.com/sikuli-tutorial-part-1/

自動IT: - (免費申請)

AutoIt的V3是一個免費的類似BASIC腳本語言設計自動化的Windows GUI和一般的腳本。它使用模擬擊鍵,鼠標移動和窗口/控制操作的組合,以便以其他語言不可能或不可靠的方式(例如VBScript和SendKeys)自動執行任務。 AutoIt也非常小巧,獨立,可以在所有版本的Windows上運行,不需要煩人的「運行時間」!

http://toolsqa.com/selenium-webdriver/autoit-selenium-webdriver/

希望它會幫助你:)

+0

藉助AppiumFor Mac應用程序,Selenium可用於Mac上桌面應用程序的自動化。請參閱鏈接https://medium.com/@rajuayyampillai/how-to-automate-any-desktop-application-d7b4615d6f1f – Amrutha

相關問題