-
Notifications
You must be signed in to change notification settings - Fork 0
/
WDIO NOTES.txt
143 lines (106 loc) · 4.26 KB
/
WDIO NOTES.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
1. TO RUN SPECIFIC SUITE OF TEST
INDICATE THE NAME OF THE SUITS IN WDIO.CONFIG AS FOLLOWS:
"scripts": {
"test": "wdio",
"actions": "wdio --suite actions",
"login": "wdio --suite login"
},
Actions and login are two suits declared above and you
run them with the commands indicated:
wdio --suite <suite name>
2. WHEN RETURNING A VALUE FROM WDIO
You can add await when returning a value from a WDIO
function by wrapping it along with the function in a
pair of brackets:
return (await function/expression)
3. USING DATA FILES IN YOUR TESTS
You can use data files to save variable names in your test
such as login username and password.
In the file, you declare a module, export it and declare
your key:value pairs
Example:
export.module = {
username : "alabi"
password : "razaq"
}
Then, in your test, you access the values with the keys
But you need to import or require the file first and
use keyword.key to access each value.
4. ADDING BASE URLS IN ENVIRONMENT VARIABLES
This will enable you to be able to run your tests with different
urls such as when you have different urls for different
environments like production env, staging env, dev env and QA env.
1. You create a file and initialize key:value pairs for each url
2. require the file in your config file at the very top
3. below the require, declare a constant to process any of
the url we indicate at runtime in terminal
4. Declare an if statement in case the url could not be fould
to display a message.
5. Change the value of the baseurl as follows:
baseUrl: url[process.env.ENV]
Example:
module.exports = {
qa: 'http://the-internet.herokuapp.com',
dev: 'https://www.google.com/',
staging: 'https://www.yahoo.com/'
}
const ENV = process.env.ENV
if (!ENV || !['qa', 'dev', 'staging'].includes(ENV)) {
console.log('Please use the following format when running the test script: ENV=qa|dev|staging')
process.exit()
}
6. To run your test, indicate your desired url by appending
Env= <envName> before the test command like this:
ENV=qa npm run actions
//linkedin
5. USING browser.debug()
browser.debug() is used to stop the browser to enable you to
inspect and interact with the browser in order to see what is
going on if there are some itches or failures. It is recommended
that you increase the timeout of your test to avoid failure due to
timeouts
6. FILE UPLOAD
To upload a file, the element: "input type button" is the most
important. It may be visible or hidden in some web app. make sure
you set it to visible before you carry out the file upload becouse you have to
be able to click on it while your test is running.
1. To make it visible, you have to disconnect it from the js code that
set it to hidden usually with the class. By setting the className to
empty, it should become visible:
document.querySelector("<selector>").className=""
Wrap the code above in browser.execute() command
browser.execute(document.querySelector("<selector>").className="")
2. //declear file path
const filePath = (path/to/file)
3. //attach path to browser
const remoteFilePath = await browser.uploadFile(filePath)
4. Attach browser path to the type file element
await MainPagePage.fileUploadButton.setValue(remoteFilePath)
5. //click the type file element
//assertion
await expect(MainPagePage.uploadedMessage).toHaveText('File Uploaded!')
If input type file is not hidden, start from step 2.
7. WORKING WITH IFRAME
A. open browser
B. Identify iframe
C. switch to iframe using browser.switchToIframe(iframe) command
D. test on any element on iframe as usual
IF YOU NEED TO CARRY OUT FURTHER TEST OUT OF THE IFRAME
A. Exit the iframe with switchToParentFrame() command
B. carry out test on any element on parent frame as usual
8. HOW TO SET UP AUTO COMPLETION
A. create a jsconfig.json file in the root folder
B. copy the following setup from wdio autocompletion page (https://webdriver.io/docs/autocompletion/), paste
it and save. add the exlude portion to it. You are good to go:
{
"compilerOptions": {
"types": [
"node",
"@wdio/globals/types",
"@wdio/mocha-framework"
]
},
"exclude": [
"node_modules"
]
}