/test/functional/android/apidemos/find/by-uiautomator-specs.js

https://github.com/jlipps/appium · JavaScript · 168 lines · 159 code · 9 blank · 0 comment · 2 complexity · 02af2f7361104a9343f9e85669da8ec8 MD5 · raw file

  1. "use strict";
  2. var setup = require("../../../common/setup-base")
  3. , desired = require("../desired")
  4. , Q = require("q");
  5. describe("apidemo - find elements - by uiautomator", function () {
  6. var driver;
  7. setup(this, desired).then(function (d) { driver = d; });
  8. it('should find elements with a boolean argument', function (done) {
  9. driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true)').then(function (els) {
  10. els.length.should.be.above(11);
  11. }).nodeify(done);
  12. });
  13. it('should find elements within the context of another element', function (done) {
  14. driver
  15. .elementByClassName('android.widget.LinearLayout').then(function (el) {
  16. el.elementsByAndroidUIAutomator('new UiSelector().className("android.widget.TextView")')
  17. .then(function (els) {
  18. els.length.should.be.above(0);
  19. els.length.should.be.below(3);
  20. });
  21. }).nodeify(done);
  22. });
  23. it('should find elements without prepending "new UiSelector()"', function (done) {
  24. driver.elementsByAndroidUIAutomator('.clickable(true)').then(function (els) {
  25. els.length.should.be.above(11);
  26. }).nodeify(done);
  27. });
  28. it('should find elements without prepending "new UiSelector()."', function (done) {
  29. driver.elementsByAndroidUIAutomator('clickable(true)').then(function (els) {
  30. els.length.should.be.above(11);
  31. }).nodeify(done);
  32. });
  33. it('should find elements without prepending "new "', function (done) {
  34. driver.elementsByAndroidUIAutomator('UiSelector().clickable(true)').then(function (els) {
  35. els.length.should.be.above(11);
  36. }).nodeify(done);
  37. });
  38. it('should ignore trailing semicolons', function (done) {
  39. driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true);')
  40. .then(function (els) {
  41. els.length.should.be.above(11);
  42. }).nodeify(done);
  43. });
  44. it('should find an element with an int argument', function (done) {
  45. driver.elementByAndroidUIAutomator('new UiSelector().index(0)').getTagName().then(function (tag) {
  46. tag.should.equal('android.widget.FrameLayout');
  47. }).nodeify(done);
  48. });
  49. it('should find an element with a string argument', function (done) {
  50. driver.elementByAndroidUIAutomator('new UiSelector().description("Animation")').then(function (el) {
  51. el.should.exist;
  52. }).nodeify(done);
  53. });
  54. it('should find an element with an overloaded method argument', function (done) {
  55. driver.elementsByAndroidUIAutomator('new UiSelector().className("android.widget.TextView")').then(function (els) {
  56. els.length.should.be.above(10);
  57. }).nodeify(done);
  58. });
  59. it('should find an element with a Class<T> method argument', function (done) {
  60. driver.elementsByAndroidUIAutomator('new UiSelector().className(android.widget.TextView)').then(function (els) {
  61. els.length.should.be.above(10);
  62. }).nodeify(done);
  63. });
  64. it('should find an element with a long chain of methods', function (done) {
  65. driver.elementByAndroidUIAutomator('new UiSelector().clickable(true).className(android.widget.TextView).index(0)').text().then(function (text) {
  66. text.should.equal('Accessibility');
  67. }).nodeify(done);
  68. });
  69. it('should find an element with recursive UiSelectors', function (done) {
  70. driver.elementsByAndroidUIAutomator('new UiSelector().childSelector(new UiSelector().clickable(true)).clickable(true)').then(function (els) {
  71. els.length.should.equal(1);
  72. }).nodeify(done);
  73. });
  74. it('should not find an element with bad syntax', function (done) {
  75. driver.elementByAndroidUIAutomator('new UiSelector().clickable((true)')
  76. .should.be.rejectedWith(/status: 9/)
  77. .nodeify(done);
  78. });
  79. it('should not find an element with a made up method', function (done) {
  80. driver.elementByAndroidUIAutomator('new UiSelector().drinkable(true)')
  81. .should.be.rejectedWith(/status: 9/)
  82. .nodeify(done);
  83. });
  84. it('should not find an element which does not exist', function (done) {
  85. driver.elementByAndroidUIAutomator('new UiSelector().description("chuckwudi")')
  86. .should.be.rejectedWith(/status: 7/)
  87. .nodeify(done);
  88. });
  89. it('should allow multiple selector statements and return the Union of the two sets', function (done) {
  90. var clickable =
  91. driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true)')
  92. .then(function (els) {
  93. els.length.should.be.above(0);
  94. return els.length;
  95. });
  96. var notClickable =
  97. driver.elementsByAndroidUIAutomator('new UiSelector().clickable(false)')
  98. .then(function (els) {
  99. els.length.should.be.above(0);
  100. return els.length;
  101. });
  102. var both =
  103. driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true); new UiSelector().clickable(false);')
  104. .then(function (els) {
  105. return els.length;
  106. });
  107. Q.all([clickable, notClickable, both]).then(function (vals) {
  108. var clickable = vals[0];
  109. var notClickable = vals[1];
  110. var both = vals[2];
  111. both.should.equal(clickable + notClickable);
  112. }).nodeify(done);
  113. });
  114. it('should remove duplicates when using multiple selectors', function (done) {
  115. var clickable = driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true)').then(function (els) {
  116. els.length.should.be.above(0);
  117. return els.length;
  118. }).fail(console.log);
  119. var clickableClickable = driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true); new UiSelector().clickable(true);').then(function (els) {
  120. els.length.should.be.above(0);
  121. return els.length;
  122. }).fail(console.log);
  123. Q.all([clickable, clickableClickable]).then(function (vals) {
  124. vals[0].should.equal(vals[1]);
  125. }).nodeify(done);
  126. });
  127. it('should find an element in the second selector if the first finds no elements', function (done) {
  128. driver.elementByAndroidUIAutomator('new UiSelector().className("not.a.class"); new UiSelector().className("android.widget.TextView")')
  129. .then(function (el) {
  130. el.should.exist;
  131. }).nodeify(done);
  132. });
  133. it('should scroll to, and return elements using UiScrollable', function (done) {
  134. driver.elementByAndroidUIAutomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).getChildByText(new UiSelector().className("android.widget.TextView"), "Views")')
  135. .text()
  136. .then(function (text) {
  137. text.should.equal("Views");
  138. }).nodeify(done);
  139. });
  140. it('should allow chaining UiScrollable methods', function (done) {
  141. driver.elementByAndroidUIAutomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).setMaxSearchSwipes(10).getChildByText(new UiSelector().className("android.widget.TextView"), "Views")')
  142. .text()
  143. .then(function (text) {
  144. text.should.equal("Views");
  145. }).nodeify(done);
  146. });
  147. it('should allow UiScrollable scrollIntoView', function (done) {
  148. driver.elementByAndroidUIAutomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Views").instance(0));')
  149. .text()
  150. .then(function (text) {
  151. text.should.equal("Views");
  152. }).nodeify(done);
  153. });
  154. it('should error reasonably if a UiScrollable does not return a UiObject', function (done) {
  155. driver.elementByAndroidUIAutomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).setMaxSearchSwipes(10)')
  156. .should.be.rejectedWith(/status: 9/)
  157. .nodeify(done);
  158. });
  159. });