Selenium代码中出现SessionNotCreatedException错误

时间:2017-03-22 04:36:53

标签: selenium-webdriver appium

package day1;

import java.net.MalformedURLException;
import java.net.URL;

import io.appium.java_client.android.AndroidDriver;

import org.openqa.selenium.remote.DesiredCapabilities;

public class bigbasket {

    public static void main(String[] args)  throws MalformedURLException, InterruptedException {
        // TODO Auto-generated method stub

        DesiredCapabilities capabilities = new DesiredCapabilities();

        // mobile details
        capabilities.setCapability("deviceName","Lenovo A6020a46");
        capabilities.setCapability("platformName","Android");
        capabilities.setCapability("platformVersion","5.1.1");

        // app details

        capabilities.setCapability("appPackage","com.bigbasket.mobileapp");
        capabilities.setCapability("appActivity","com.bigbasket.mobileapp.activity.HomeActivity");


        // appium server or launching the app

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

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

        Thread.sleep(5000);

        String expected_result = "Raw mango- Diced";    


        // click on search button

        //driver.findElementByXPath("//*[@index='1'][@text='Search products'][@class='android.widget.EditText']").click();

        driver.findElementById("com.bigbasket.mobileapp:id/homePageSearchBox").click();

        Thread.sleep(2000);


        // enter the diced mango in search option and click

        driver.findElementById("com.bigbasket.mobileapp:id/searchView").sendKeys("Raw mango diced");



        //click on add button
        driver.findElementById("com.bigbasket.mobileapp:id/btnAddToBasket").click();

        // add to cart
        driver.findElementById("com.bigbasket.mobileapp:id/cartcountView").click();

        // verify that added item is diced mango

        String act_output = driver.findElementById("com.bigbasket.mobileapp:id/txtProductDesc").getText();


        if ( act_output== expected_result)
        { 
            System.out.println("pass");
        }
        else
        {
            System.out.println("fail");
        }

我收到此错误:

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Permission to start activity denied.) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 9.02 seconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: '5CG6420X0K', ip: '192.168.1.4', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: io.appium.java_client.android.AndroidDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)`enter code here`

如何更正?

0 个答案:

没有答案