无法创建具有所需功能的新远程会话

时间:2019-03-19 12:59:43

标签: java selenium appium appium-android

我想通过使用硒网格在两个设备上并行执行。通过建立JSON,为每个设备运行Appium桌面,一切都顺利完成。

与appium建立连接

public class ApplicationHandling {

public static AndroidDriver driver;
public static ExtentTest test;
public static ExtentReports extent;
//public static boolean waitForPresenceOfElelment;
public static ConfigFileReader cfg;

public  ApplicationHandling()
{
    cfg = new ConfigFileReader();
    System.out.println("Inside application handling constructor");
    Date date=new Date();
    SimpleDateFormat dateFormatFolder = new SimpleDateFormat("dd_MMM_yyyy");
    File ResultDir = new File(System.getProperty("user.dir")+File.separator+"/FrameworkReports/"+dateFormatFolder.format(date));
    System.out.println(ResultDir);
    // Defining Directory/Folder Name
    if (!ResultDir.exists()){  // Checks that Directory/Folder Doesn't Exists!
        ResultDir.mkdir();
    }
    SimpleDateFormat dateFormat=new SimpleDateFormat("dd_MMM_yyyy_hh_mm_ssaa");
    extent=new ExtentReports(ResultDir +"/" +"Report"+""+dateFormat.format(date)+".html",false);
}

public static RemoteWebDriver getInstance()
{
    System.out.println("remote webdriver");
    return driver;
}

@Parameters({"device","version"})
@BeforeTest(alwaysRun = true)
public static void setUp(String device,String version) throws MalformedURLException, InterruptedException {
    DesiredCapabilities cap = new DesiredCapabilities();

    cap.setCapability("platformName", "Android");
    cap.setCapability("deviceName", device);
    cap.setCapability("noReset", true);
    cap.setCapability(CapabilityType.VERSION,version);
    cap.setCapability("automationName", cfg.getAutomationName());
    cap.setCapability ("appPackage", cfg.getAppPackage());
    cap.setCapability ("appActivity", cfg.getAppActivity());

    System.out.println("Before Suite Execution started");
    System.out.println("Driver:"+driver);
    System.out.println("URL:"+cfg.getApplicationUrl());
    System.out.println("cap: "+cap);

    driver = new AndroidDriver<MobileElement>(new URL(cfg.getApplicationUrl()), cap);
    System.out.println(driver);
}


JSON:

{
  "capabilities":
  [
    {
      "deviceName": "Redmi",
      "platformName": "Windows",
      "browserName":"Android",
      "platformVersion": "7.0",
      "maxInstances": 1
    }
  ],
  "configuration":
  {
    "cleanUpCycle":2000,
    "timeout":30000,
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "url":"http://0.0.0.0:4723/wd/hub",
    "host": "0.0.0.0",
    "port": 4723
    "maxSession": 1,
    "register": true,
    "registerCycle": 5000,
    "hubPort": "4444",
    "hubHost": "127.0.0.1"
  }
}


Testng.xml

<test name="test_redmi">
    <parameter name="device" value="Redmi"/>
    <parameter name="version" value="7.0"/>
    <classes>
        <class name="Tests.LoginTest">
             <methods>
                 <include name="loginOTP"/>
             </methods>
        </class>
    </classes>


错误日志

  

org.openqa.selenium.remote.ProtocolHandshake createSession   INFO:退回到直接的W3C远端连接

     

org.openqa.selenium.SessionNotCreatedException:无法创建新的远程会话。所需功能=功能[{appPackage =“ com.amhi.healthjinn”,appActivity =“ com.amhi.healthjinn.MainActivity”,noReset = true,automationName = uiautomator2,platformName = Android,deviceName = Moto E,版本= 7.1.2 }],所需功能=功能[{}]   构建信息:版本:“未知”,修订版:“ 1969d75”,时间:“ 2016-10-18 09:43:45 -0700”

->在创建驱动程序实例时出现错误。

1 个答案:

答案 0 :(得分:0)

我最近从Appium Desktop切换到Appium Studio,因为它们支持并行执行,并且具有用于以Java,C#,Ruby等不同语言设置框架的插件。 阅读this文档以获取有关并行执行的更多信息。