How to use field.getText method in Appium

Best JavaScript code snippet using appium

Run Appium automation tests on LambdaTest cloud grid

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

event_filters_spec.js

Source: event_filters_spec.js Github

copy
1// Protractor Jasmine end-to-end (e2e) test.
2//
3// See https://github.com/angular/protractor/blob/master/docs/getting-started.md
4//
5
6var EventsPage = require('./events_page').EventsPage,
7    page = new EventsPage();
8
9xdescribe('event filters', function () {
10
11    beforeEach(function () {
12        var width = 1200, height = 800;
13        browser.driver.manage().window().setSize(width, height);
14        page.get();
15    });
16
17    afterEach(function () {
18        browser.executeScript('window.localStorage.clear();');
19    });
20
21    describe('filtering results', function () {
22
23        beforeEach(function () {
24            page.filterByText('Something');
25            page.filterBy('Status', 'Ingesting');
26            page.filterBy('Source', 'Twitter');
27        });
28
29        it('displays the selected filters', function () {
30            expect(page.filter.field.getText()).toContain('Status: Ingesting');
31            expect(page.filter.field.getText()).toContain('Source: Twitter');
32        });
33
34        it('clears the filter when asked to', function () {
35            page.filter.clearButton.click();
36            expect(page.filter.field.getText()).not.toContain('Status: Ingesting');
37            expect(page.filter.field.getText()).not.toContain('Sources: Twitter');
38        });
39
40        it('restores filters when reloading the page', function () {
41            page.get();
42            expect(page.filter.field.getText()).toContain('Status: Ingesting');
43            expect(page.filter.field.getText()).toContain('Source: Twitter');
44            expect(page.filter.textFilter.getAttribute('value')).toContain('Something');
45        });
46    });
47
48    describe('filter profiles', function () {
49        beforeEach(function () {
50            page.filterBy('Status', 'Ingesting');
51            page.filterBy('Source', 'Twitter');
52
53            page.profile.menuButton.click();
54        });
55
56        it('allows saving the current filters', function () {
57            expect(page.profile.profiles.getText()).not.toContain('My Filter');
58
59            expect(page.profile.nameField.isDisplayed()).toBe(false);
60            page.profile.formButton.click();
61
62            expect(page.profile.nameField.isDisplayed()).toBe(true);
63
64            page.profile.nameField.sendKeys('My Filter');
65            page.profile.saveButton.click();
66
67            page.profile.menuButton.click();
68
69            expect(page.profile.profiles.getText()).toContain('My Filter');
70            expect(page.profile.activeProfile.getText()).toEqual('My Filter');
71        });
72
73        describe('with a previous filter', function () {
74            beforeEach(function () {
75                page.profile.formButton.click();
76                page.profile.nameField.sendKeys('Twitter');
77                page.profile.saveButton.click();
78
79                page.filterBy('Status', 'Recording');
80                page.filterBy('Source', 'Facebook');
81            });
82
83            it('saves a new profile', function () {
84                page.profile.menuButton.click();
85                page.profile.formButton.click();
86                page.profile.nameField.sendKeys('Facebook');
87                page.profile.saveButton.click();
88                page.profile.menuButton.click();
89
90                expect(page.profile.profiles.getText()).toContain('Twitter');
91                expect(page.profile.profiles.getText()).toContain('Facebook');
92                expect(page.profile.activeProfile.getText()).toEqual('Facebook');
93            });
94        });
95
96        describe('loading a profile', function () {
97            beforeEach(function () {
98                page.profile.formButton.click();
99                page.profile.nameField.sendKeys('Twitter');
100                page.profile.saveButton.click();
101
102                page.filterBy('Status', 'Recording');
103                page.filterBy('Source', 'Facebook');
104
105                page.profile.menuButton.click();
106                page.profile.formButton.click();
107                page.profile.nameField.sendKeys('Facebook');
108                page.profile.saveButton.click();
109                page.profile.menuButton.click();
110            });
111
112            it('restores saved filters', function () {
113                expect(page.filter.field.getText()).toContain('Status: Recording');
114                expect(page.filter.field.getText()).toContain('Source: Facebook');
115
116                element(by.linkText('Twitter')).click();
117
118                expect(page.filter.field.getText()).toContain('Status: Ingesting');
119                expect(page.filter.field.getText()).toContain('Source: Twitter');
120            });
121
122            it('persists across page reload', function () {
123                element(by.linkText('Twitter')).click();
124
125                expect(page.filter.field.getText()).toContain('Status: Ingesting');
126                expect(page.filter.field.getText()).toContain('Source: Twitter');
127
128                page.get();
129
130                expect(page.filter.field.getText()).toContain('Status: Ingesting');
131                expect(page.filter.field.getText()).toContain('Source: Twitter');
132
133                page.profile.menuButton.click();
134
135                expect(page.profile.profiles.getText()).toContain('Twitter');
136                expect(page.profile.profiles.getText()).toContain('Facebook');
137            });
138        });
139
140        describe('editing a profile', function () {
141            beforeEach(function () {
142                page.profile.formButton.click();
143                page.profile.nameField.sendKeys('Twitter');
144                page.profile.saveButton.click();
145
146                page.filterBy('Status', 'Recording');
147                page.filterBy('Source', 'Facebook');
148
149                page.profile.menuButton.click();
150                page.profile.formButton.click();
151                page.profile.nameField.sendKeys('Facebook');
152                page.profile.saveButton.click();
153                page.profile.menuButton.click();
154            });
155
156            it('renames', function () {
157                page.profile.editButtons.get(1).click();
158                page.profile.nameField.sendKeys(' Edited');
159                page.profile.saveButton.click();
160                page.profile.menuButton.click();
161
162                expect(page.profile.profiles.getText()).toContain('Twitter');
163                expect(page.profile.profiles.getText()).toContain('Facebook Edited');
164            });
165        });
166    });
167});
168
Full Screen

auth.js

Source: auth.js Github

copy
1describe('Registration', function() {
2  var fnameField, lnameField, emailField, passwordField;
3
4  beforeEach(function() {
5    fnameField = element(by.id('name'));
6    lnameField = element(by.id('lname'));
7    emailField = element(by.id('email'));
8    passwordField = element(by.id('password'));
9  });
10
11  it('page fields should be empty', function() {
12    browser.get('/#/register');
13
14    expect(fnameField.getText()).toEqual('');
15    expect(lnameField.getText()).toEqual('');
16    expect(passwordField.getText()).toEqual('');
17    expect(emailField.getText()).toEqual('');
18  });
19
20  it('should require all fields to be filled', function(){
21    fnameField.sendKeys('Doe');
22
23    element(by.name('button')).click();
24
25    expect(browser.getCurrentUrl()).toMatch(/\/#\/register/);
26    fnameField.clear();
27  });
28
29  it('should create a new user', function(){
30    fnameField.sendKeys("Johnny");
31    lnameField.sendKeys("Does");
32    emailField.sendKeys("[email protected]");
33    passwordField.sendKeys("doespassword");
34
35    element(by.name('button')).click();
36
37    expect(browser.getCurrentUrl()).toMatch(/\/#\/login/);
38  });
39});
40
41describe('Login', function(){
42  var emailField, passwordField;
43
44  beforeEach(function() {
45    emailField = element(by.id('email'));
46    passwordField = element(by.id('password'));
47  });
48
49  it('page fields should be empty', function() {
50    browser.get('/#/login');
51
52    expect(passwordField.getText()).toEqual('');
53    expect(emailField.getText()).toEqual('');
54  });
55
56  it('should require all fields to be filled', function(){
57    element(by.name('button')).click();
58
59    var errorMsg = element(by.css('.text-danger'));
60    expect(errorMsg.getText()).toBe('Wrong email/password.');
61  });
62
63  it('should succeed with valid credentials', function(){
64    emailField.sendKeys("[email protected]");
65    passwordField.sendKeys("doespassword");
66
67    element(by.name('button')).click();
68
69    expect(browser.getCurrentUrl()).toMatch(/\/#\//);
70    expect(element(by.css('.page')).getText()).toBe("Dashboard");
71  })
72});
73
Full Screen

tableview.js

Source: tableview.js Github

copy
1var $webfx = {title: "TableView Example"};
2
3/**
4function addPerson(event) {
5        ObservableList<Person> data = tableView.getItems();
6        data.add(new Person(firstNameField.getText(),
7            lastNameField.getText(),
8            emailField.getText()
9        ));
10        
11        firstNameField.setText("");
12        lastNameField.setText("");
13        emailField.setText("");   
14    }
15    **/
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 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)