How to use runTextEditTest method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

Run Appium Android Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

android-keyboard-base.js

Source: android-keyboard-base.js Github

copy
1"use strict";
2
3var env = require('../../helpers/env')
4  , setup = require("./setup-base")
5  , _ = require('underscore')
6  , getAppPath = require('../../helpers/app').getAppPath;
7
8
9var desired = {
10  app: getAppPath('ApiDemos'),
11  appActivity: '.view.TextFields',
12  newCommandTimeout: 90
13};
14if (env.SELENDROID) {
15  desired.automationName = 'selendroid';
16}
17
18module.exports = function () {
19  var driver;
20
21  var runTextEditTest = function (testText, done) {
22    var el;
23    driver
24      .waitForElementByClassName('android.widget.EditText')
25      .then(function (_el) { el = _el; })
26      .then(function () {
27        if (env.SELENDROID) {
28          return el.clear();
29        }
30      })
31      .then(function () { return el.sendKeys(testText); })
32      .then(function () { return el.text().should.become(testText); })
33      .nodeify(done);
34  };
35
36  var runEditAndClearTest = function (testText, done) {
37    var el;
38    driver
39      .waitForElementByClassName('android.widget.EditText')
40      .then(function (_el) { el = _el; })
41      .then(function () {
42        if (env.SELENDROID) {
43          return el.clear();
44        }
45      })
46      .then(function () { return el.sendKeys(testText).text().should.become(testText); })
47      .then(function () {
48        return el.clear().should.not.be.rejected;
49      })
50      .then(function () {
51        // Selendroid and uiautomator have different ways of dealing with
52        // hint text. In particular, Selendroid does not return it
53        // and uiautomator does.
54        var expectedText = "hint text";
55        if (env.SELENDROID) {
56          expectedText = "";
57        }
58        return el.text().should.become(expectedText);
59      })
60      .nodeify(done);
61  };
62
63  describe('editing ascii text field', function () {
64    setup(this, desired).then(function (d) { driver = d; });
65
66    it('should be able to edit a text field', function (done) {
67      var testText = "Life, the Universe and Everything.";
68      runTextEditTest(testText, done);
69    });
70
71    it('should be able to edit and manually clear a text field', function (done) {
72      var testText = "The answer is 42.";
73      runEditAndClearTest(testText, done);
74    });
75
76    it('should be able to send &-', function (done) {
77      var testText = '&-';
78      runTextEditTest(testText, done);
79    });
80
81    it('should be able to send & and - in other text', function (done) {
82      var testText = 'In the mid-1990s he ate fish & chips as mayor-elect.';
83      runTextEditTest(testText, done);
84    });
85
86    it('should be able to send - in text', function (done) {
87      var testText = 'Super-test.';
88      runTextEditTest(testText, done);
89    });
90  });
91
92  describe('editing unicode text field', function () {
93    setup(this,  _.defaults({
94      unicodeKeyboard: true,
95      resetKeyboard: true
96    }, desired)).then(function (d) { driver = d; });
97
98    it('should be able to edit a text field', function (done) {
99      var testText = "Life, the Universe and Everything.";
100      runTextEditTest(testText, done);
101    });
102
103    it('should be able to edit and manually clear a text field', function (done) {
104      var testText = "The answer is 42.";
105      runEditAndClearTest(testText, done);
106    });
107
108    it('should be able to send &-', function (done) {
109      var testText = '&-';
110      runTextEditTest(testText, done);
111    });
112
113    it('should be able to send & and - in other text', function (done) {
114      var testText = 'In the mid-1990s he ate fish & chips as mayor-elect.';
115      runTextEditTest(testText, done);
116    });
117
118    it('should be able to send - in text', function (done) {
119      var testText = 'Super-test.';
120      runTextEditTest(testText, done);
121    });
122
123    it('should be able to send - in unicode text', function (done) {
124      var testText = 'परीक्षा-परीक्षण';
125      runTextEditTest(testText, done);
126    });
127
128    it('should be able to send & in text', function (done) {
129      var testText = 'Fish & chips';
130      runTextEditTest(testText, done);
131    });
132
133    it('should be able to send & in unicode text', function (done) {
134      var testText = 'MÄ«na & chips';
135      runTextEditTest(testText, done);
136    });
137
138    it('should be able to send roman characters with diacritics', function (done) {
139      var testText = 'Áé Œ ù ḍ';
140      runTextEditTest(testText, done);
141    });
142
143    it('should be able to send a u with an umlaut', function (done) {
144      var testText = 'ü';
145      runTextEditTest(testText, done);
146    });
147
148    // skipping because clear doesn't work reliably on RTL scripts
149    it.skip('should be able to send Arabic', function (done) {
150      var testText = 'تجريب';
151      runTextEditTest(testText, done);
152    });
153
154    // skipping because clear doesn't work reliably on RTL scripts
155    it.skip('should be able to send Hebrew', function (done) {
156      var testText = 'בדיקות';
157      runTextEditTest(testText, done);
158    });
159
160    it('should be able to send Tamil', function (done) {
161      var testText = 'சோதனை';
162      runTextEditTest(testText, done);
163    });
164
165    it('should be able to send Gujarati', function (done) {
166      var testText = 'પરીક્ષણ';
167      runTextEditTest(testText, done);
168    });
169
170    it('should be able to send Chinese', function (done) {
171      var testText = '测试';
172      runTextEditTest(testText, done);
173    });
174
175    it('should be able to send Russian', function (done) {
176      var testText = 'тестирование';
177      runTextEditTest(testText, done);
178    });
179
180    describe('pressing device key with unicode keyboard', function () {
181      // skip selendroid because selendroid implements keyevent with an adb
182      // call, and we are unable to send metastate that way
183      it('should be able to send combination keyevents @skip-selendroid-all', function (done) {
184        driver
185          .waitForElementByClassName('android.widget.EditText')
186            .clear()
187          .pressDeviceKey(29, 193)
188          .elementByClassName('android.widget.EditText')
189            .text().should.become('A')
190          .nodeify(done);
191      });
192    });
193  });
194};
195
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium Android Driver on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)