所需功能已贬值,如何使其与Android驱动程序配合使用?

时间:2018-09-19 14:42:00

标签: c# android selenium appium appium-android

我目前正在尝试使用Appium / Selenium启动自动化项目,并注意到DesiredCapabilities已贬值。有没有人有可行的解决方法示例或此方法的新实现?

using System;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Appium.Enums;
using OpenQA.Selenium.Remote;

namespace LeaflyAutomation
{
    public class TC1
    {

        public AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL(sc_url), caps);

        public void InitDriver()
        {
            //No longer valid, need new driver setup
            DesiredCapabilities caps = new DesiredCapabilities();

            caps.SetCapability("PlatformName", "Android");
            caps.SetCapability("appPackage"), "myapp file path");
            caps.SetCapability("appActivity", "com.demo.demofolder.activities.MainActivity");



        }
    }
}

enter image description here

2 个答案:

答案 0 :(得分:1)

  

您为DesiredCapabilities导入了错误的库。

import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
public class TC1
{

    public static AppiumDriver<MobileElement> driver;

    public void InitDriver()
    {

    DesiredCapabilities caps=new DesiredCapabilities();
    caps.setCapability("appPackage", "your app package name");
    caps.setCapability("appActivity", "your app activity name");
    caps.setCapability("deviceName", "Android phone");
    caps.setCapability("platform","Android");

    driver = new AndroidDriver<MobileElement>(new URL(
            "http://127.0.0.1:4723/wd/hub"), caps);

    }
}

有关更多信息,请访问Step by Step Appium Tutorial for Beginners

答案 1 :(得分:1)

DesiredCapabilities are depreciated in latest version , we can use AppiumOptions to pass device detail instead of DesiredCapabilities. 

                  AppiumOptions capabilities = new AppiumOptions();
                  capabilities.AddAdditionalCapability("platformName", "Android");
                  capabilities.AddAdditionalCapability("app", "APK_Path");
                  capabilities.AddAdditionalCapability("udid", "Device_ID");
                  capabilities.AddAdditionalCapability("deviceName", "Android");
                  capabilities.AddAdditionalCapability("noReset", false);
                  driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities);