简体   繁体   中英

Appium when started Programmatically, the Android Driver fails to Initialize

I have been trying to launch the Appium Server programatically and then based on the Process output, would initialize the Android Driver and run some tests. However, everytime the Appium Server is launched from the program, the execution stalls on the initialization of the Android Driver.

Here is my method for Starting the server:

private boolean StartServer(String strCommand)
{
    try
    {
        rtCommand = Runtime.getRuntime();
        proc = rtCommand.exec(strCommand);

        BufferedReader stdInput = new BufferedReader(new 
             InputStreamReader(proc.getInputStream()));

        //Checking output of Appium Server Initialization
        String s = null;
        while ((s = stdInput.readLine()) != null)
        {
            System.out.println(s);
            if (s.contains("Console LogLevel: debug"));
                return true;
        }
    }
    catch (Exception ex)
    {
        System.out.println("Error in starting Appium Server. Stack Trace below:");
        ex.printStackTrace();
        return false;
    }
    return false;
}

Now, My TestNG annotation @BeforeClass holds the following code:

@BeforeClass
public void setUp() throws MalformedURLException
{
    StartServer("cmd /c \"\"C:/Program Files (x86)/nodejs/node.exe\" \"C:/Program Files (x86)/Appium/node_modules/appium/lib/server/main.js\" --address 127.0.0.1 --port 4723 --platform-name Android --platform-version 23 --automation-name Appium --log-no-color --udid 3100aeb26c6a2363\"");

    FrameworkDriver objFrameworkDriver = new FrameworkDriver();

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName", "ec5bee97");
    capabilities.setCapability("BROWSER_NAME", Android");
    capabilities.setCapability("VERSION", "5.1.1");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("appPackage", "com.XX.AA");
    capabilities.setCapability("appActivity", "com.XX.AA.BB");
    strProjectDir = "<MyProjectLoc>";

    try
    {
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }

    System.out.println();
}

The execution halted here:

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

Try using something like version 5.1.1, instead of platform-version 23 in your start server command line. (The same version as defined in capabilities in your code)

StartServer("cmd /c \"\"C:/Program Files (x86)/nodejs/node.exe\" \"C:/Program Files (x86)/Appium/node_modules/appium/lib/server/main.js\" --address 127.0.0.1 --port 4723 --platform-name Android --version 5.1.1 --automation-name Appium --log-no-color --udid 3100aeb26c6a2363\"");

Appium wants to the OS version of the Android device instead of the API level

Also, ensure that the device name used while defining capabilities is same as that defined in start server command line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM