构造函数RemoteWebDriver(Capabilities)引用缺少的类型Capabilities

时间:2015-12-08 05:11:59

标签: android testing appium

我正在使用Appium for android 我想设置DesiredCapabilities,如下所示:

DesiredCapabilities capabilities = new DesiredCapabilities();
         capabilities.setCapability("BROWSER_NAME", "Android");
           capabilities.setCapability("platformName", "Android");
            capabilities.setCapability("deviceName", "Android");

capabilities.setCapability("appPackage","com.gauravdubey.gdlearning");  
            capabilities.setCapability("appActivity","com.gauravdubey.gdlearning.MainActivity");


(下面的行给出错误 - 构造函数RemoteWebDriver(Capabilities)引用缺少的类型Capabilities)

WebDriver driver=new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);

然而,该定义要求同样的事情 - 一个Url obejct和一个Desired Capabilities。
我找不到确切的问题。
更新: 我尝试将 RemoteWebDriver 更改为 AndroidDriver - 然后它说:
类型org.openqa.selenium.remote.service.DriverService $ Builder无法解析。它是从所需的.class文件间接引用的。 添加的依赖项是
•Java-client-2.1.0.jar •Selenium-server-standalone-2.46.0.jar

2 个答案:

答案 0 :(得分:0)

您应该遵循以下要求:

        import unittest
        from selenium import webdriver
        from selenium.webdriver.common.keys import Keys

    class Googletest(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Firefox()
        def test_log_to_system(self):
            driver = self.driver
            driver.get("http://www.google.com")
            self.assertIn("Google", driver.title)
            elem = driver.find_element_by_name("q")
            elem.send_keys("hello")
            elem.send_keys(Keys.RETURN)
            assert "No results found." not in driver.page_source
         def tearDown(self):
            self.driver.close()

    if __name__ == "__main__":
        unittest.main()

你必须拥有 class Googletest(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() def test_log_to_system(self): driver = self.driver driver.get("http://www.google.com") self.assertIn("Google", driver.title) elem = driver.find_element_by_name("q") elem.send_keys("hello") elem.send_keys(Keys.RETURN) assert "No results found." not in driver.page_source def tearDown(self): self.driver.close() if __name__ == "__main__": unittest.main() 的依赖关系。 应该这样工作(为我工作)。

<强>更新 发现缺少DesiredCapabilities capabilities = new DesiredCapabilities() capabilities.setCapability(CapabilityType.BROWSER_NAME, browserName) capabilities.setCapability(CapabilityType.VERSION, version) capabilities.setCapability(MobileCapabilityType.PLATFORM, platformName) capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName) capabilities.setCapability(MobileCapabilityType.UDID, deviceID) capabilities.setCapability(MobileCapabilityType.APP, appLocationPath) def URL remoteAddress = new URL("http://$hubIP:4444/wd/hub") this.androidDriver = new AndroidDriver(remoteAddress, capabilities) 依赖关系。它可以添加io.appium:java-client:3.2.0org.seleniumhq.selenium:selenium-remote-driver:<version>

答案 1 :(得分:-1)

从构建路径中删除Selenium jar。只添加java-client jar来构建路径。

通过它,您可以在java代码中使用以下功能。我在我的java项目中使用相同的功能。

    File app = new File("absolute-apk-path-of-your-app");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION,"your-device-android-version");
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"your-device-id");
    capabilities.setCapability(MobileCapabilityType.APP, app);
    capabilities.setCapability("deviceName","your-device-name");
    capabilities.setCapability("appPackage", "your-app-pckg-name");
    capabilities.setCapability("appActivity", "your-app-activity");
    capabilities.setCapability("appWaitActivity", "your-app-wait-activity-if-app-has");
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);