Mac OS上的桌面应用程序自动化

时间:2017-08-08 11:46:27

标签: java selenium-webdriver desktop-application

我正在尝试在Mac上自动化桌面应用程序。我写了以下代码:

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 个答案:

答案 0 :(得分:0)

Selenium仅用于自动化Web应用程序。

如果您需要自动化桌面应用程序,可以尝试以下任何框架: -

  • QTP
  • Sikuli
  • 自动IT

QTP介绍: - (付费申请)

QTP代表Hewlett Packard(HP)的产品QuickTest Professional。一旦脚本开发完成,该工具可帮助测试人员无缝监控地执行自动功能测试。 HP QTP使用Visual Basic Sc​​ripting(VBScript)自动化应用程序。 https://www.guru99.com/quick-test-professional-qtp-tutorial-1.html

Sikuli: - (免费申请)

Sikuli自动化您在屏幕上看到的任何内容。它使用图像识别来识别和控制GUI组件。当无法轻松访问GUI的内部或源代码时,它非常有用。

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

Auto-IT: - (免费申请)

AutoIt v3是一种免费的类似BASIC的脚本语言,用于自动化Windows GUI和通用脚本。它使用模拟击键,鼠标移动和窗口/控制操作的组合,以便以其他语言(例如VBScript和SendKeys)不可能或不可靠的方式自动执行任务。 AutoIt也非常小,独立,可以在开箱即用的所有Windows版本上运行,不需要烦人的“运行时”!

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

希望它会对你有所帮助:)。