Robotium Robotium 测试 Webvew 的时候,solo 的 webUrl 未更新跳转的问题

爻施 · 2016年07月11日 · 1066 次阅读

我的 APP 是一个混合的应用,以下是我的测试代码

      solo.waitForActivity(".activity.MainActivity",2000);
      solo.clickOnText("我的");
//进入登录页面并进行登录操作
      solo.assertCurrentActivity("aa",LoginActivity.class);
      solo.sleep(2000);
      EditText username= (EditText) solo.getView(R.id.id_phone_ed);
      EditText password= (EditText) solo.getView(R.id.id_password_ed);
      Button login_btn= (Button) solo.getView(R.id.id_login_bt);
      solo.enterText(username,"1111111111");
      solo.enterText(password,"123456789");
      solo.clickOnView(login_btn);
      solo.waitForActivity(".activity.MainActivity",3000);
  //登录成功后跳转到主页面
      solo.clickOnText("我的");
      solo.sleep(2000);
      System.out.println(solo.getWebUrl());
//寻找设置按钮
      solo.clickOnWebElement(By.xpath("//*[@id='user']/ul[2]/a[4]"));
      System.out.println(solo.getWebUrl());
      WebElement logout=solo.getWebElement(By.xpath("//*[text()='退出登录']"),0);
      solo.clickOnWebElement(logout);

这是日志:


5229-25229/com.hupan.app E/com.hupan.hupanandroid:MPAWebViewClient: ---------onPageStarted--------------:http:///app/h5/page/myw.html
07-11 15:11:57.396 25229-25263/com.hupan.app E/com.hupan.hupanandroid:: http:///app/h5/page/myw.html->/data/data/com.hupan.app/files/offline/page/myw.html
07-11 15:11:57.894 25229-25263/com.hupan.app E/com.hupan.hupanandroid:: http:///app/h5/common/zepto.min.js->/data/data/com.hupan.app/files/offline/common/zepto.min.js
07-11 15:11:57.895 25229-25263/com.hupan.app E/com.hupan.hupanandroid:: http:///app/h5/common/m-base1.0.1.js->/data/data/com.hupan.app/files/offline/common/m-base1.0.1.js
07-11 15:11:57.897 25229-25263/com.hupan.app E/com.hupan.hupanandroid:: http:///app/h5/common/appreset.css->/data/data/com.hupan.app/files/offline/common/appreset.css
07-11 15:11:57.899 25229-25263/com.hupan.app E/com.hupan.hupanandroid:: http:///app/h5/common/hupan.css->/data/data/com.hupan.app/files/offline/common/hupan.css
07-11 15:11:57.900 25229-25263/com.hupan.app E/com.hupan.hupanandroid:: http:///app/h5/common/hupan.js->/data/data/com.hupan.app/files/offline/common/hupan.js
07-11 15:11:57.908 25229-25263/com.hupan.app E/com.hupan.hupanandroid:: http:///app/h5/page/newAct.js->/data/data/com.hupan.app/files/offline/page/newAct.js
07-11 15:11:57.911 25229-25263/com.hupan.app E/com.hupan.hupanandroid:: http:///app/h5/page/newAct.css->/data/data/com.hupan.app/files/offline/page/newAct.css
07-11 15:11:57.973 25229-25229/com.hupan.app W/MPAWebViewChromeClient: The key "target-densitydpi" is not supported.
07-11 15:11:57.984 25229-25263/com.hupan.app E/com.hupan.hupanandroid:: http://114.55187.18/app/h5/page/unknow.png->/data/data/com.hupan.app/files/offline/page/unknow.png
07-11 15:11:57.993 25229-25263/com.hupan.app E/com.hupan.hupanandroid:MPAWebViewClient: Load http://hpdaily.img-cn-hangzhou.aliyuncs.com/608229_app_1464006332390.jpg@80Q_1pr.jpg
07-11 15:11:57.999 25229-25263/com.hupan.app E/com.hupan.hupanandroid:MPAWebViewClient: Load http:///rest/getActMsg.json
07-11 15:11:58.003 25229-25263/com.hupan.app E/com.hupan.hupanandroid:: http://app/h5/common/iconfont.woff->/data/data/com.hupan.app/files/offline/common/iconfont.woff
07-11 15:11:58.038 25229-25229/com.hupan.app E/com.hupan.hupanandroid:MPAWebViewClient: ---------onPageFinished--------------:http://114.55.187.18/app/h5/page/myw.html
07-11 15:11:58.040 25229-25263/com.hupan.app E/com.hupan.hupanandroid:MPAWebViewClient: Load http://114.55.187.18/favicon.ico
07-11 15:11:58.052 25229-25263/com.hupan.app E/com.hupan.hupanandroid:MPAWebViewClient: Load http://114.55.187.18/rest/getAct.json?status=1
**07-11 15:11:59.742 25229-25251/com.hupan.app I/System.out: http:///app/h5/axis/viewpointw.html**
07-11 15:12:10.447 25229-25229/com.hupan.app E/com.hupan.hupanandroid:HuPanCourseFragment: >>onPause
07-11 15:12:10.448 25229-25229/com.hupan.app E/com.hupan.hupanandroid:HuPanCourseFragment: >>onPause
07-11 15:12:10.452 25229-25229/com.hupan.app E/com.hupan.hupanandroid:MainActivity: pause()
07-11 15:12:10.554 25229-25229/com.hupan.app W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection
07-11 15:12:10.791 25229-25229/com.hupan.app E/com.hupan.hupanandroid:HuPanCourseFragment: >>onStop
07-11 15:12:10.791 25229-25229/com.hupan.app E/com.hupan.hupanandroid:HuPanCourseFragment: >>onStop
07-11 15:12:10.800 25229-25229/com.hupan.app I/Native: InetIO_SetForeground 0
07-11 15:12:10.800 25229-25229/com.hupan.app E/com.hupan.hupanandroid:HuPanCourseFragment: >>onDestroyView
07-11 15:12:10.864 25229-25229/com.hupan.app E/com.hupan.hupanandroid:HuPanCourseFragment: onDestroy
07-11 15:12:10.865 25229-25229/com.hupan.app E/com.hupan.hupanandroid:HuPanCourseFragment: >>onDetach
07-11 15:12:10.865 25229-25229/com.hupan.app E/com.hupan.hupanandroid:HuPanForumFragment: onDestroy
07-11 15:12:10.866 25229-25229/com.hupan.app E/com.hupan.hupanandroid:HuPanCourseFragment: >>onDestroyView
07-11 15:12:10.900 25229-25229/com.hupan.app E/com.hupan.hupanandroid:HuPanCourseFragment: onDestroy
07-11 15:12:10.901 25229-25229/com.hupan.app E/com.hupan.hupanandroid:HuPanCourseFragment: >>onDetach
07-11 15:12:11.458 25229-25251/com.hupan.app I/TestRunner: failed: testDemo(com.hupan.app.activity.MainActivityTest)
07-11 15:12:11.459 25229-25251/com.hupan.app I/TestRunner: ----- begin exception -----
07-11 15:12:11.461 25229-25251/com.hupan.app I/TestRunner: junit.framework.AssertionFailedError: WebElement with xpath: '//*[@id='user']/ul[2]/a[4]' is not found!
                                                               at junit.framework.Assert.fail(Assert.java:50)
                                                               at com.robotium.solo.Clicker.clickOnWebElement(Clicker.java:414)
                                                               at com.robotium.solo.Solo.clickOnWebElement(Solo.java:1328)
                                                               at com.robotium.solo.Solo.clickOnWebElement(Solo.java:1297)
                                                               at com.hupan.app.activity.MainActivityTest.testDemo(MainActivityTest.java:55)
                                                               at java.lang.reflect.Method.invokeNative(Native Method)
                                                               at java.lang.reflect.Method.invoke(Method.java:515)
                                                               at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
                                                               at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
                                                               at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
                                                               at junit.framework.TestCase.runBare(TestCase.java:134)
                                                               at junit.framework.TestResult$1.protect(TestResult.java:115)
                                                               at junit.framework.TestResult.runProtected(TestResult.java:133)
                                                               at junit.framework.TestResult.run(TestResult.java:118)
                                                               at junit.framework.TestCase.run(TestCase.java:124)
                                                               at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
                                                               at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
                                                               at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
                                                               at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
07-11 15:12:11.462 25229-25251/com.hupan.app I/TestRunner: ----- end exception -----

在登录后,就是再次点击 “我的” 按钮之后,url 应该是 http:///app/h5/page/myw.html,但是我 system.out 的却是 http:///app/h5/axis/viewpointw.html,这个 url 应该是我第一次代开 Activity 时获取的 url,
请问这个怎么解决

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册