51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 3340|回复: 4
打印 上一主题 下一主题

[Appium] 求助:初学appium, 运行脚本模拟器上无法正常打开浏览器

[复制链接]
  • TA的每日心情
    开心
    2017-6-27 16:22
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]测试小兵

    跳转到指定楼层
    1#
    发表于 2016-3-22 17:57:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    1.  模拟器表面现象:


    2. eclipse 报错:
    错误1: FAILED CONFIGURATION: @AfterClass afterTestStopDriver
    org.openqa.selenium.remote.SessionNotFoundException:
    Command duration or timeout: 5 milliseconds
    Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
    System info: host: '本机名', ip: '本机IP', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_05'
    Driver info: io.appium.java_client.android.AndroidDriver
    Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=39.0.0.0, platform=ANDROID, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
    Session ID: 9c31a71dedea66f57122e5ea098a9d71
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    错误2:
    FAILED: runChromeWebBrowser
    org.openqa.selenium.remote.SessionNotFoundException: no such session
      (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 581 milliseconds
    Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
    System info: host: '本机名', ip: '本机IP', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_05'
    Driver info: io.appium.java_client.android.AndroidDriver
    Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=39.0.0.0, platform=ANDROID, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
    Session ID: 9c31a71dedea66f57122e5ea098a9d71
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)




    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有帐号?(注-册)加入51Testing

    x
    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2017-6-27 16:22
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]测试小兵

    2#
     楼主| 发表于 2016-3-22 18:00:04 | 只看该作者
    3.appium 日志:
    > info: [debug] Found emulator nexusS_intelAtom in port 5554
    > info: [debug] Setting device id to emulator-5554
    > info: [debug] Did not launch AVD because it was already running.
    > info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
    > info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s emulator-5554 wait-for-device
    > info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s emulator-5554 shell "echo 'ready'"
    > info: [debug] Starting logcat capture
    > info: [debug] Pushing unlock helper app to device...
    > info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s emulator-5554 install "C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
    > info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s emulator-5554 shell "dumpsys window"
    > info: [debug] Screen already unlocked, continuing.
    > info: [debug] Forwarding system:4724 to device:4724
    > info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s emulator-5554 forward tcp:4724 tcp:4724
    > info: [debug] Pushing appium bootstrap to device...
    > info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s emulator-5554 push "C:\\Program Files (x86)\\Appium\\node_modules\\appium\\build\\android_bootstrap\\AppiumBootstrap.jar" /data/local/tmp/
    > info: Starting App
    > info: [debug] Attempting to kill all 'uiautomator' processes
    > info: [debug] Getting all processes with 'uiautomator'
    > info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s emulator-5554 shell "ps 'uiautomator'"
    > info: [debug] No matching processes found
    > info: [debug] Running bootstrap
    > info: [debug] spawning: D:\android-sdk-windows\platform-tools\adb.exe -s emulator-5554 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.android.browser -e disableAndroidWatchers false
    > info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
    > info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
    > info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
    > info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
    > info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
    > info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
    > info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
    > info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
    > info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
    > info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
    > info: [debug] Pushing command to appium work queue: ["getDataDir",{}]
    > info: [debug] [BOOTSTRAP] [debug] Loading json...
    > info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
    > info: [debug] dataDir set to: /data
    > info: Chromedriver: Changed state to 'starting'
    > info: Chromedriver: Set chromedriver binary as: C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe
    > info: Chromedriver: Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (`netstat -nao ^| findstr /R /C:"9515 "`) do (FOR /F "usebackq" %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe`) do (IF NOT %b=="" TASKKILL /F /PID %a))
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2017-6-27 16:22
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]测试小兵

    3#
     楼主| 发表于 2016-3-22 18:00:32 | 只看该作者
    4.  我的脚本就是一个目的,打开百度首页。
    脚本如下:
    import io.appium.java_client.android.AndroidDriver;

    import java.io.File;
    import java.io.IOException;
    import java.net.URL;
    import java.util.concurrent.TimeUnit;

    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.By;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.testng.Assert;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.Test;

    public class OpenChrom {
        AndroidDriver<WebElement> driver;

        /**
         * @author Young
         * @throws IOException
         */
        public void startRecord() throws IOException {
            Runtime rt = Runtime.getRuntime();
            // this code for record the screen of your device
            rt.exec("cmd.exe /C adb shell screenrecord /sdcard/runCase.mp4");

        }

        @BeforeClass(alwaysRun = true)
        public void setUp() throws Exception {
            // set up appium

            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability(CapabilityType.BROWSER_NAME, "browser");
            capabilities.setCapability("platformName", "Android");
            capabilities.setCapability("deviceName", "Android Emulator");
            capabilities.setCapability("platformVersion", "5.1.1");
            driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
            startRecord();

        }

        @Test
        public void runChromeWebBrowser() {
            driver.get("http://www.baidu.com");
            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
            System.out.println(driver.getTitle());
            snapshot((TakesScreenshot) driver, "before_search.png");
            driver.findElementByXPath("//textarea[@id='index-kw']").sendKeys(
                    "appium");
            driver.findElement(By.xpath("//button[@id='index-bn']")).click();
            driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
            System.out.println(driver.getTitle());
            snapshot((TakesScreenshot) driver, "after_search.png");
            Assert.assertTrue(driver.getTitle().contains("appium"));

        }

       
       
        /**
         * This Method create for take screenshot
         *
         * @author Young
         * @param drivername
         * @param filename
         */
        public static void snapshot(TakesScreenshot drivername, String filename) {
            // this method will take screen shot ,require two parameters ,one is
            // driver name, another is file name

            String currentPath = System.getProperty("user.dir"); // get current work
                                                                    // folder
            File scrFile = drivername.getScreenshotAs(OutputType.FILE);
            // Now you can do whatever you need to do with it, for example copy
            // somewhere
            try {
                System.out.println("save snapshot path is:" + currentPath + "/"
                        + filename);
                FileUtils
                        .copyFile(scrFile, new File(currentPath + "\\" + filename));
            } catch (IOException e) {
                System.out.println("Can't save screenshot");
                e.printStackTrace();
            } finally {
                System.out.println("screen shot finished, it's in " + currentPath
                        + " folder");
            }
        }

        @AfterClass
        public void afterTestStopDriver() {
            driver.quit();
        }
    }
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2017-6-27 16:22
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]测试小兵

    4#
     楼主| 发表于 2016-3-22 18:01:37 | 只看该作者
    我手动打开浏览器很快,不会有这个问题。 我用的是intel x86
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    无聊
    2016-8-18 09:20
  • 签到天数: 3 天

    连续签到: 1 天

    [LV.2]测试排长

    5#
    发表于 2016-3-22 18:49:49 | 只看该作者
    你没加延时等待

    评分

    参与人数 1测试积点 +10 收起 理由
    lsekfe + 10 积极回复获得测试积点10

    查看全部评分

    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-11-22 03:09 , Processed in 0.071150 second(s), 26 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表