2017-08-08 353 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

相关问题