You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by cx...@apache.org on 2017/03/29 12:13:29 UTC

[02/39] incubator-weex git commit: * [test] add recycler test

* [test] add recycler test


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/1d9fbd6d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/1d9fbd6d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/1d9fbd6d

Branch: refs/heads/0.12-dev
Commit: 1d9fbd6dc59d312eb8608af84400e48c35c03eec
Parents: 670d001
Author: \u9690\u98ce <cx...@apache.org>
Authored: Thu Mar 23 16:32:45 2017 +0800
Committer: \u9690\u98ce <cx...@apache.org>
Committed: Thu Mar 23 16:32:45 2017 +0800

----------------------------------------------------------------------
 test/scripts/components/recycler.test.js | 77 +++++++++++++++------------
 1 file changed, 44 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1d9fbd6d/test/scripts/components/recycler.test.js
----------------------------------------------------------------------
diff --git a/test/scripts/components/recycler.test.js b/test/scripts/components/recycler.test.js
index c134b67..f091e1f 100644
--- a/test/scripts/components/recycler.test.js
+++ b/test/scripts/components/recycler.test.js
@@ -7,105 +7,116 @@ var path = require('path');
 var os = require('os');
 var util = require("../util.js");
 
+
+const platform = process.env.platform.toLowerCase() || 'android';
+const isAndroid = platform === 'android';
+
+let cell1Path = isAndroid ? '//recycler[1]/div[3]/' : '//recycler[1]/cell[1]/'
+let cell2Path = isAndroid ? '//recycler[1]/div[4]/' : '//recycler[1]/cell[2]/'
+let cell3Path = isAndroid ? '//recycler[1]/div[5]/' : '//recycler[1]/cell[3]/'
+let cell4Path = isAndroid ? '//recycler[1]/div[6]/' : '//recycler[1]/cell[4]/'
+
 const isApproximate = (x, y) =>  {
-  return Math.abs(x - y) < 0.1
+  return Math.abs(x - y) <= 1
 }
 
+
 describe('recycler', function () {
   this.timeout(util.getTimeoutMills())
   const driver = util.createDriver(wd)
 
   before(function () {
+    console.log('wxpage://' + util.getDeviceHost() +'/components/recycler.js')
     return util.init(driver)
       .get('wxpage://' + util.getDeviceHost() +'/components/recycler.js')
-      .waitForElementByXPath('//div[1]/text[1]',util.getGETActionWaitTimeMills(),1000)
+      .waitForElementByXPath('//recycler[1]',util.getGETActionWaitTimeMills(),1000)
   });
 
   after(function () {
-      return util.quit(driver);
+      // return util.quit(driver);
   })
 
   let scaleFactor = 0
   let screenHeight = 0
+  let recyclerWidth = 0
   let navBarHeight = 0
+  let cell1Height = 0
+  let cell2Height = 0
   it('#1 test recyler layout', () => {
     return driver
     .getWindowSize()
     .then(size=>{
       scaleFactor = size.width / 750
       screenHeight = size.height
+      recyclerWidth = isAndroid ? (size.width + 12) : 750 * scaleFactor
+      console.log(`screen size:${JSON.stringify(size)}`)
+      console.log(`scale factor:${scaleFactor}`)
     })
     .sleep(2000)
     .elementByXPath('//recycler[1]')
     .getRect()
     .then((rect)=>{
-      console.log(`scale factor:${scaleFactor}`)
       console.log(`recycler rect:${JSON.stringify(rect)}`)
       navBarHeight = rect.y
       assert.isOk(isApproximate(rect.x, 0))
-      assert.isOk(isApproximate(rect.width, 750 * scaleFactor))
+      assert.isOk(isApproximate(rect.width, recyclerWidth))
       assert.isOk(isApproximate(rect.height, screenHeight - navBarHeight))
     })
-  })
-
-  it('#2 test header 1 layout', () => {
-    return driver
     .elementByXPath('//recycler[1]/div[1]/')
     .getRect()
     .then((rect)=>{
       console.log(`header 1 rect:${JSON.stringify(rect)}`)
       assert.isOk(isApproximate(rect.x, 0))
       assert.isOk(isApproximate(rect.y, navBarHeight))
-      assert.isOk(isApproximate(rect.width, 750 * scaleFactor))
+      assert.isOk(isApproximate(rect.width, recyclerWidth))
       assert.isOk(isApproximate(rect.height, 377 * scaleFactor))
     })
-  })
-
-  it('#3 test header 2 layout', () => {
-    return driver
     .elementByXPath('//recycler[1]/div[2]/')
     .getRect()
     .then((rect)=>{
       console.log(`header 2 rect:${JSON.stringify(rect)}`)
       assert.isOk(isApproximate(rect.x, 0))
       assert.isOk(isApproximate(rect.y, navBarHeight + 377 * scaleFactor))
-      assert.isOk(isApproximate(rect.width, 750 * scaleFactor))
+      assert.isOk(isApproximate(rect.width, recyclerWidth))
       assert.isOk(isApproximate(rect.height, 94 * scaleFactor))
     })
-  })
-
-  it('#4 test cell 1 layout', () => {
-    return driver
-    .elementByXPath('//recycler[1]/cell[1]/')
+    .elementByXPath(cell1Path)
     .getRect()
     .then((rect)=>{
       console.log(`cell 1 rect:${JSON.stringify(rect)}`)
+      cell1Height = rect.height
       assert.isOk(isApproximate(rect.x, 0))
       assert.isOk(isApproximate(rect.y, navBarHeight + 471 * scaleFactor))
       assert.isOk(isApproximate(rect.width, 369 * scaleFactor))
-      assert.isOk(isApproximate(rect.height, 502 * scaleFactor))
     })
-  })
-
-  it('#5 test cell 2 layout', () => {
-    return driver
-    .elementByXPath('//recycler[1]/cell[2]/')
+    .elementByXPath(cell2Path)
     .getRect()
     .then((rect)=>{
       console.log(`cell 2 rect:${JSON.stringify(rect)}`)
+      cell2Height = rect.height
+      assert.isOk(isApproximate(rect.x, 381 * scaleFactor), 'x not approximate:' + 381 * scaleFactor)
+      assert.isOk(isApproximate(rect.y, navBarHeight + 471 * scaleFactor), 'y not approximate:' + (navBarHeight + 471 * scaleFactor))
+      assert.isOk(isApproximate(rect.width, 369 * scaleFactor))
+    })
+    .elementByXPath(cell3Path)
+    .getRect()
+    .then((rect)=>{
+      console.log(`cell 3 rect:${JSON.stringify(rect)}`)
       assert.isOk(isApproximate(rect.x, 381 * scaleFactor))
-      assert.isOk(isApproximate(rect.y, navBarHeight + 471 * scaleFactor))
+      assert.isOk(isApproximate(rect.y, navBarHeight + 471 * scaleFactor + cell2Height))
+      assert.isOk(isApproximate(rect.width, 369 * scaleFactor))
+    })
+    .elementByXPath(cell4Path)
+    .getRect()
+    .then((rect)=>{
+      console.log(`cell 4 rect:${JSON.stringify(rect)}`)
+      assert.isOk(isApproximate(rect.x, 0 * scaleFactor))
+      assert.isOk(isApproximate(rect.y, navBarHeight + 471 * scaleFactor + cell1Height))
       assert.isOk(isApproximate(rect.width, 369 * scaleFactor))
-      assert.isOk(isApproximate(rect.height, 472 * scaleFactor))
     })
-  })
-
-  it('#10 test fixed', () => {
-    return driver
     .elementByXPath('//div[1]')
     .getRect()
     .then((rect)=>{
-      console.log(`scale factor:${scaleFactor}`)
       console.log(`fixed rect:${JSON.stringify(rect)}`)
       assert.isOk(isApproximate(rect.x, 640 * scaleFactor))
       assert.isOk(isApproximate(rect.y, screenHeight - 110 * scaleFactor))