You are on page 1of 7

NOTE :

//at first this IT didnt run fully , i thought the code is not working
but ...
//i understood that if any error occurs ..it will stop there and will
not go to next line of the code ..
//so it didnt exeute the next line ofthe code.

1.If we want to point out span ..we have to point the parent too .

await $("//*[text()='CLICK ME!']/..")


2. waitForClickable()

//waitForClickable() ..there is a DEFAULT time in 'wdio-spec' such as 10000..


//it will wait for 10,000ms for the element to appear to be
clickable...
//if we wanna change the default time ..we can use
waitForClickable({timeout:45000})
If it fails , it will show an error and will not proceed to the next line .So in this case we use try and
catch exception .

Try and catch …if any error occurred …it will catch the error and proceed with next steps .

Refer Logindaily.js

WaitforDisplay()-Check for the element in the Web.

waitforExist()- checks if the element is present in the DOM even if the element is not visible in the
webpage.

waitUntil()-

await Loading.waitUntil(async function() {

//It sees whther the text is === given text ....if its not ...it will
wait for given time(15000) and
// will throw out an error saying the timed out ..the text didnt
appear.
return (await Loading.getText())==='LOADING COMPLETE.'},{
timeout:15000,
timeoutMsg:'timed out123'
})
Here it take more than 10,000 ms to get the required text ….so timeout is necessary.

waitForDisplay() isDisplayed()
Its an asynchronous Boolean function..it checks It is a synchronous Boolean fuction . It checks
repeatedly for the element whether it is immediately .It returns true ..if the element is
displayed for a specified time and returns an present and returns false if the element is not
error if it is not displayed. there.

ef
3.Addvalue() = goes on adding the value without clearing

Such as in a text box Hellohi..

await FirstName.addValue('Hello')
await browser.pause(5000)
await FirstName.addValue('Hi')
await browser.pause(5000)
await FirstName.setValue('How are you!')
await browser.pause(5000)
await FirstName.clearValue()
await browser.pause(5000)
SetValue() = it will first clear the previous entries and then inserts the value.

ClearValue() – Will clear out the value fully.

4. Expect is an assertion inorder to ensure the value or string is correct .

It return the Boolean result.

a.toHaveValueContaining() = compare STRING.

await expect(dropdown).toHaveValueContaining('java123')
b.toEqual()= Boolean fucntion

await expect(radio1_isDisplayed).toEqual(true)

5. Dropdown:

We can select by

a. Attribute
b. Index
c. C.Visible text.
Here Ignorecase mean to ignore the casesensitive …we have searched ‘CSS’ and expecting
‘css’ …which is not same in JS …but when ignorecase is used case sensitive is ignored.
d. const dropdown = await $('#dropdowm-menu-1')
e. await dropdown.selectByAttribute('value','java');
f. await expect(dropdown).toHaveValueContaining('java123')
g. browser.pause(200000)
h. const dropdown2= await $('#dropdowm-menu-2')
i. await dropdown2.selectByIndex(3)
j. await expect(dropdown2).toHaveValueContaining('jUnit',
{ignoreCase:true})
k. await browser.pause(2000)
l. const dropdown3= await $('#dropdowm-menu-3')

ef
m. await dropdown3.selectByVisibleText('CSS')
n. await browser.pause(2000)
o. await expect(dropdown3).toHaveValueContaining('css',
{ignoreCase:true})
p. await browser.pause(2000)

6.Actions
a. dragAndDrop

b.doubleClick()

c.hover= moveTo()

await browser.url('https://www.webdriveruniversity.com/Actions/index.html')
const drag = await $('#draggable')
const targetto= await $ ('#droppable')
await drag.dragAndDrop(targetto)
//dragAndDrop is a function ..which is used to drag the particular
element and drop it in the target .
await browser.pause(4000)
//2.
const doubleclick1 = await $('#double-click')
await doubleclick1.doubleClick();
await hover.moveTo()

7,Iframe – read the comments very important.

const iframe = await $('#frame')


await browser.pause(4000)
await browser.switchToFrame(iframe)
//if we wanna click or do some action on IFRAME ..first we have to
switch to it..
//if not we will get an error such as.."element wasnt found".
await browser.pause(4000)
const producrs = await $('//a[@href="products.html"]')
await producrs.click();
await browser.pause(4000)
// await browser.switchToParentFrame()
//here theres only one frame, so theres no parentframe.

8.We can also goto new window .using

Await browser.newWindow(‘window locator’)

Inorder to switch to new window – use

Await browser.switchWindow(‘req window locator’)

ef
9.Alert –read this important.

The reason why using toHaveTextContaining() might result in "Undefined string" is


that the getAlertText() method does not return a Web Element, but rather a string.

The toHaveTextContaining() method expects a Web Element as its subject, and


then it checks if the text of that element contains a given substring.

In contrast, the toEqual() method is used to compare two string values, which
makes it suitable for comparing the expected and actual alert text.

Therefore, in this case, it is appropriate to use toEqual() instead of


toHaveTextContaining(), as we are comparing two strings to check for an exact
match between the expected and actual alert text.

10.Alert –

a. acceptAlert()
b. dismissAlert()
c. c.getAlerttext()- will return a string.

If we use getAlertText() ..then for assertion we should use toEqual() only.

11. In order to upload the file …we have addValue(‘locationOfTheFile’)

await (await $
('#myFile')).addValue('C:/Users/swetha.senthilkumar/Desktop/Webdriverio-
framework - Practise/test/specs/Data/dummay_fileUpload.txt')
11. browser.execute { }

This is in my case ..used for force click on locator…which is not actually a button.

It forced clicked on the calender number …

Same way …it is used to execute complex task ..

Inorder to change the backgroundcolor of the page..it is impossible using normal wdio
commands ..so we use browser.execute

await browser.execute( ()=>


{
return document.body.style.backgroundColor="yellow"
})
LEARN BASICS OF JS Injection.

April 11, 23-

If the class is ”d-none”, then the contents of the class will be hidden ., so we cannot get the text
of that locator using getText.

ef
So I used the ‘id’ to locate .Then Parsed (converts str to obj) ….JSON.parse(str)

// MachinReportOEECheck.js

Eg: //tbody[@id="tableContents"]/tr/td//span[@class="d-none deviceStatus"]


April 20,2023

To execute specific file .

npx wdio - -spec test/spec/constac.js

npx wdio wdio.conf.js --spec test\specs\ProductionPlan\ProductionQuality.js

To execute and exclude the files and folders.

Npm wdio --spec test/spec/webdriveruniversity/*.spec.js --exclude


test/spec/webdriveruniversirty/test1.js

suites :{
smoke :['test/specs/Data/MachineStatusAPI.js',
'test/specs/Data/wait-command.js',
'test/specs/Data/add-items-to-basket.js'
],
example :[ 'test/specs/Data/wait-command.js',
'test/specs/Data/add-items-to-basket.js']
},//npx wdio --suite smoke
//it is used to run files from different folder .
//where as , npx wdio --spec location (either single file or folder)
Package.json..enter script :

Npm run testname.

Allure reports.

1. npm install -g allure-commandline


2. 2. npm install -g @wdio/cli
3. Tried running wdio wdio.conf.js error cause of restrictions

Because Get-ExecutionPolicy is restricted for us. So contacted IT people to change to


‘Unrestricted’

4.Run the test using normal command npx wdio

5.Generate JSON file using : allure generate allure-results –clean

ef
6. Open in Browser using “: allure open(The reports will be generated in the browser)

7.If needed run the command line : npm install -g allure-commandline

To run only a specific test use = it.only

To skip specific tests use = it.skip

If a test has to be completed within specific time = this.timeout(30000)..if it exceeds above


30000..Error will be thrown.

May 15,2023

Val()= is used to get the current value and also set the value[its jQuery]

Eg: const Date= await $('//input[@id="inputDate"]')

Date.val()

//It will get the current value in that selector.

Then Date.val(‘2023-05-18’)

//This sets the given date in the date textbox ..but is not updated in the
DatetimePicker .

//To get updated ..use the trigger the ‘event listener’

Here the event listener is dp.change…It is triggered when the date has to be
changed.

$('#inputDate').val(date).trigger('dp.change');

Wdio geckodriver update :

npm install geckodriver@latest --save-dev

Inorder to get the value form ‘input’ tag we should use

getValue.

const FirstShift = await $('//input[@id="productionCount_1"]')


console.log("zebra,",await FirstShift.getValue());

June 1 , 2023

ef
JS- Math.random() will generate the numbers bet 0 & 1 …but not 1 .

ef

You might also like