-
Notifications
You must be signed in to change notification settings - Fork 3
/
section_20_notes.txt
25 lines (20 loc) · 2.17 KB
/
section_20_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
'browser.execute(script, arguments)' - Inject a snippet of JavaScript into the page for execution in the context of
the currently selected frame. The executed script is assumed to be synchronous and the result of evaluating the
script is returned to the client.
The script argument defines the script to execute in the form of a function body. The value returned by that
function will be returned to the client. The function will be invoked with the provided args array and the
values may be accessed via the arguments object in the order specified.
Arguments may be any JSON-primitive, array, or JSON object. JSON objects that define a WebElement reference
will be converted to the corresponding DOM element. Likewise, any WebElements in the script result will be
returned to the client as WebElement JSON objects.
1. We can also execute commands or scripts inline with established pages to test functionality, e.g: Playing
or pausing a video on a webpage by using console in developers tools of your browser. 'execute()' will allow
us to add these inline with our test.
2. Creating Seperate Classes - Create a new folder in the root directory and call it 'pageObjects'. To centralize our
resourses, we will create a class file in the new folder and move our selectors and other reusuable resources in this file using 'get' method.
After creating the file with get methods, we will update our 'wdio.conf.js' file. In the 'specs' object modify the path to read './tests/*.js' and
in the 'exclude' object add the new path to './pageObjects' folder with files, 'pageObjects/*_Page.js'. Go to the new file we creatd, 'ContactUs_Page.js'
and at the end add 'module.export = new ContactUs_Page();' so we can use this file in our project. In the 'contactUsTest.js' file, remove unecessary
selectors and add 'var ContactUs_Page = require("./pageObjects/ContactUs_Page.js");' at the top of the file. On the method located inside the decribe
block on the 'contactUsTest.js' file, we will remove the 'browser.setValue()' and replace it with 'ContactUs_Page.firstname.setValue()'.
3. In the 3rd pahse, we cetralize all selectors and commnds inside the POM class and simply the test by applying all concepts.