How to use isDisplayed method in Webdriverio

Best JavaScript code snippet using webdriverio-monorepo

Run Webdriverio automation tests on LambdaTest cloud grid

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

elementsExist.js

Source: elementsExist.js Github

copy
1import sel from '../../data/selectors';
2import exp from '../../data/expected.json';
3
4describe('My Little Hero', function () {
5
6    describe('Getting to the page', function () {
7
8        before('Open App', function () {
9            browser.url('');
10        });
11
12        it('TC-001 Page Title is MLH trial ', function () {
13            let title = browser.getTitle();
14            browser.pause(2000);
15            expect(title).toEqual('MLH trial');
16        });
17
18    });
19
20    describe('Elements exist', function () {
21
22        it('TC-002 Header is present ', function () {
23            let header = $(sel.header).isDisplayed();
24            expect(header).toEqual(true);
25        });
26
27        it('TC-003 Instruction is present ', function () {
28            let instruction = $(sel.instruction).isDisplayed();
29            expect(instruction).toEqual(true);
30        });
31
32        it('TC-004 Name field label is present ', function () {
33            let label = $$(sel.requiredLabel)[0].isDisplayed();
34            expect(label).toEqual(true);
35        });
36
37        it('TC-005 Name field is present', function () {
38            let name = $(sel.name).isDisplayed();
39            expect(name).toEqual(true);
40        });
41
42        it('TC-006 Gender radio buttons  label is present', function () {
43            let label = $$(sel.requiredLabel)[1].isDisplayed();
44            expect(label).toEqual(true);
45        });
46
47        it('TC-007.a Gender radio buttons is present', function () {
48            let button = $$(sel.radioButtons)[0].isDisplayed();
49            expect(button).toEqual(true);
50        });
51
52        it('TC-007.b Gender radio buttons is present', function () {
53            let button = $$(sel.radioButtons)[1].isDisplayed();
54            expect(button).toEqual(true);
55        });
56
57        it('TC-007.c Gender radio buttons is present', function () {
58            let button = $$(sel.radioButtons)[2].isDisplayed();
59            expect(button).toEqual(true);
60        });
61
62        it('TC-008 Age field  label is present', function () {
63            let label = $$(sel.requiredLabel)[2].isDisplayed();
64            expect(label).toEqual(true);
65        });
66
67        it('TC-009 Age field  is present', function () {
68            let age = $(sel.age).isDisplayed();
69            expect(age).toEqual(true);
70        });
71
72        it('TC-010 Story Type dropdown label is present', function () {
73            let label = $$(sel.requiredLabel)[3].isDisplayed();
74            expect(label).toEqual(true);
75        });
76
77        it('TC-011 Story Type dropdown is present', function () {
78            let dropdown = $(sel.storyType).isDisplayed();
79            expect(dropdown).toEqual(true);
80        });
81
82        it('TC-012 Image field  label is present', function () {
83            let label = $$(sel.imageLabel)[4].isDisplayed();
84            expect(label).toEqual(true);
85        });
86
87        it('TC-013 Image field  is present', function () {
88            let image = $(sel.image).isDisplayed();
89            expect(image).toEqual(true);
90        });
91
92        it('TC-014 Submit button  is present', function () {
93            let button = $(sel.submit).isDisplayed();
94            expect(button).toEqual(true);
95        });
96
97    });
98
99
100});
101
102
103
104
Full Screen

findFirstAllowedEndpoint.test.js

Source: findFirstAllowedEndpoint.test.js Github

copy
1import findFirstAllowedEndpoint, { generateArrayOfLinks } from '../findFirstAllowedEndpoint';
2
3describe('ADMIN | SettingsPage | utils', () => {
4  describe('findFirstAllowedEndpoint', () => {
5    it('should return null if there is no sections', () => {
6      expect(findFirstAllowedEndpoint([])).toBeNull();
7    });
8
9    it('should return null if all links are hidden', () => {
10      const data = [
11        {
12          id: 'global',
13          links: [
14            {
15              to: 'global.test',
16              isDisplayed: false,
17            },
18            {
19              to: 'global.test2',
20              isDisplayed: false,
21            },
22          ],
23        },
24        {
25          id: 'test',
26          links: [
27            {
28              to: 'test.test',
29              isDisplayed: false,
30            },
31            {
32              to: 'test.test2',
33              isDisplayed: false,
34            },
35          ],
36        },
37      ];
38
39      expect(findFirstAllowedEndpoint(data)).toBeNull();
40    });
41
42    it('should return the destination of the first displayed link', () => {
43      const data = [
44        {
45          id: 'global',
46          links: [
47            {
48              to: 'global.test',
49              isDisplayed: false,
50            },
51            {
52              to: 'global.test2',
53              isDisplayed: false,
54            },
55          ],
56        },
57        {
58          id: 'test',
59          links: [
60            {
61              to: 'test.test',
62              isDisplayed: false,
63            },
64            {
65              to: 'test.test2',
66              isDisplayed: true,
67            },
68            {
69              to: 'test.test3',
70              isDisplayed: true,
71            },
72          ],
73        },
74        {
75          id: 'test1',
76          links: [
77            {
78              to: 'test1.test',
79              isDisplayed: true,
80            },
81            {
82              to: 'test1.test2',
83              isDisplayed: true,
84            },
85            {
86              to: 'test1.test3',
87              isDisplayed: true,
88            },
89          ],
90        },
91      ];
92
93      expect(findFirstAllowedEndpoint(data)).toEqual('test.test2');
94    });
95  });
96
97  describe('generateArrayOfLinks', () => {
98    it('should return an empty array', () => {
99      expect(generateArrayOfLinks([])).toEqual([]);
100    });
101
102    it('should return an array containing all the links', () => {
103      const data = [
104        {
105          id: 'global',
106          links: [
107            {
108              to: 'global.test',
109              isDisplayed: false,
110            },
111            {
112              to: 'global.test2',
113              isDisplayed: false,
114            },
115          ],
116        },
117        {
118          id: 'test',
119          links: [
120            {
121              to: 'test.test',
122              isDisplayed: false,
123            },
124            {
125              to: 'test.test2',
126              isDisplayed: true,
127            },
128            {
129              to: 'test.test3',
130              isDisplayed: true,
131            },
132          ],
133        },
134        {
135          id: 'test1',
136          links: [
137            {
138              to: 'test1.test',
139              isDisplayed: true,
140            },
141            {
142              to: 'test1.test2',
143              isDisplayed: true,
144            },
145            {
146              to: 'test1.test3',
147              isDisplayed: true,
148            },
149          ],
150        },
151      ];
152      const expected = [
153        {
154          to: 'global.test',
155          isDisplayed: false,
156        },
157        {
158          to: 'global.test2',
159          isDisplayed: false,
160        },
161        {
162          to: 'test.test',
163          isDisplayed: false,
164        },
165        {
166          to: 'test.test2',
167          isDisplayed: true,
168        },
169        {
170          to: 'test.test3',
171          isDisplayed: true,
172        },
173        {
174          to: 'test1.test',
175          isDisplayed: true,
176        },
177        {
178          to: 'test1.test2',
179          isDisplayed: true,
180        },
181        {
182          to: 'test1.test3',
183          isDisplayed: true,
184        },
185      ];
186
187      expect(generateArrayOfLinks(data)).toEqual(expected);
188    });
189  });
190});
191
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 Webdriverio 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)