Selenium JS Keywords


Selenium used in JavaScript involves using a set of commands and methods to interact with web elements and perform actions on web pages. Here we will discuss some of the commonly used functions and methods in Selenium with JavaScript: 


How to use Keywords?


Keywords are used by calling them in a test step and adding the input and expected output data values. If you want to capture the dynamic objects, you can also add properties of the object in the test object column. Let's understand this with an example of using the AccessibilityCheckpointSettings keyword.


1. AccessibilityCheckpointSettings



Accessibility Testing is a subset of Usability Testing and it is performed to ensure that the application being tested is usable by people with disabilities like hearing, color blindness, old age and other disadvantaged groups.

This keyword sets the prerequisites for Accessibility Test. It takes the report name of the Accessibility Test and the location where the Accessibility Report of a page after creation will be stored.

It will check the Accessibility of the current page and will generate the Accessibility Report of that particular page at the location or path given by the user.


For example, to do checkpoint settings in an application to make it accessible to users, we can use the following steps :-



1. Add a new step in your test case by clicking the + icon at the top. Search AccessbilityCheckpointSettings and click on the search result to add it to the new test step.

 

2. Click on the downward arrow in the input data column of the step to open the input data window for the keyword.


3. Add the input data as shown below and click on Ok button. 

Suppose you want to sets the prerequisites for Accessibility Test then, here is how you will use AccessibilityCheckPointsSettings keyword.


AccessibilityCheckPointsSettings 

Report Name

ABC

Report Folder Path


ALS




Note: We have illustrated the requirement of the Test Object, Input Data, and corresponding Output data values in the tables following this image. These values are filled as per the requirement of the keyword used in the test case as shown in the image below. We have given similar tables for each keyword for illustration. 



In this Keyword, there was no requirement to add a Test Object's properties, hence, we have mentioned it is not required.


Test Object 


Test Object Required

Description

None

This keyword does not require any Object input argument.


Input Data

 Input Data Required

 Description 

ReportName

 

* It is of String type.

* It takes the name of the report to be created.

                      ReportFolderPath

* It is of String type.

* It takes the path(location) where Accessibility Report will be saved after creation.

 


Output Data

Condition

Output value

If the keyword passes successfully

True

if there is an error

False



Common Error conditions

Scenarios

Error Message

Debug Information

If Data Input Argument is not given

Argument Data Missing

 

Argumnent(s): (ReprtName; ReportFolderPath) is/are blank.


Now let's go through the list of various keywords to understand their functionality. 



2. SetViewPort

This keyword sets the Page Layout according to the given dimensions. It is basically used to open any website/browser in the Mobile View.


Example

Suppose you want to set the Page Layout according to the given dimensions, then you can use SetViewPort keyword as follows:


SetViewPort

Width

412

Height

732

Browser with Width “412” & Height “732”


Test Object 


Test Object Required

Description

None

This keyword does not require any Object input argument.


Input Data

 Input Data Required

 Description 

Width

 

* It is of Integer type.

* It takes the width of the page.

Height

* It is of Integer type.

* It takes the height of the page.


Output Data

Condition

Output value

If the keyword passes successfully

True

if there is an error

False



Common Error conditions

Scenarios

Error Message

Debug Information

If Data Input Argument is not given

Argument Data Missing

 

Argument(s): (Width;Height) is/are blank.



3. ValidatePageAccessibility

This keyword validates the Page Accessibility at run time and will generate an Accessibility Report which contains the required page Accessibility.


Test Object 


Test Object Required?

Description

No

This keyword does not require any Object input argument.


Input Data

 Input Data Required?

 Description 

No

This keyword does not require any Data Input argument. 


Output Data

Condition

Output value

If the keyword passes successfully

True

if there is an error

False



Error conditions


There are no error conditions for this keyword.

.

4. VisualCheckPointsForObjects

This keyword takes the objects and test the location of the objects relatively to each other on a page. This keyword creates and compare different layout among different objects.

This keyword will take minimum of 10 objects. 

Example

Suppose you want to takes the objects and test the location of the objects relatively to each other on a page then, here is how you will use VisualCheckPointsForObjects keyword.


VisualCheckPointsForObjects

SpecFile Name

LIFE

SpecFolder Path

xls

 

Test Object 


Test Object Required?

Description

Object (1-10)


This keyword requires an Object as an object input argument.

Note: You can Provide 10 Objects at a time with this keyword


Input Data

 Input Data Required?

 Description 

SpecFileName

* It is of String type.

* It takes the name of the Spec (Objects) file.

* It is created once.

 

SpecFolderPath

* It is of String type.

*It takes the path(location) where SpecFile will be saved after creation.

 



Output Data

Condition

Output value

If the keyword passes successfully

True

if there is an error

False




Error conditions

Conditions

Error Message

Debug Information

If no object is provided

Argument Data Missing

 

Data not provided for argument:'Object1; Object2; Object3; Object4; Object5; Object6; Object7; Object8; Object9; Object10'. Expected StaticValue was empty

 

5. VisualCheckPointsForPage

VisualCheckPointForPage keyword is basically used to compare a page with the already captured same page at runtime.

This keyword compares the page image by breaking image into given numbers of rows and columns.

This keyword when run for the first time will capture the current page snapshot and then the snapshot  will be compared with the same page when it will run for the second time. If there will be any differences, it will highlight the area of differences.

Example

Suppose you want to compare a page with the already captured same page at runtime then, here is how you will use VisualCheckPointForPage keyword.

VisualCheckPointForPage

Image

Name

XYZ

Should

Overlay

False

Number

OfRows

 

20

NumberOf

Columns

20

Test Object 


Test Object Required?

Description

No

This keyword does not require any Object input argument.


Input Data

 Input Data Required?

 Description 

ImageName

* It is of String type.

* It takes the name of the image to be captured.

 

ShouldOverlay

* It is of Boolean type.

* By default it is False.

* If it is False, it will highlight the image with Red dotted lines.

* If it is True, it will highlight the image with Green overlay.

 


NumberOfRows

* It is of Integer type.

* It is the number of rows in which image will be divided.

* By default, number of rows are 10.

 


NumberOfColumns

* It is of Boolean type.

* By default it is False.

* If it is False, it will create the Spec(Objects) File.

* If it is True, it will compare the Specs(Objects) and will create a Visual QA Report.



Output Data

Condition

Output value

If the keyword passes successfully

True

if there is an error

False



Error conditions


There are no error conditions for this keyword.

 

6. VisualCheckPointSetting

This keyword sets prerequisites for the Visual QA. It takes the required settings need to perform the Visual QA on responsive websites.


Example

Suppose you want to sets prerequisites for the Visual QA then, here is how you will use VisualCheckPointSetting keyword.

VisualCheckPointSetting

SpecFile Name

ABC

SpecFolder Path

Platform

Desktop

ValidateBaseline

False

Approximation Range

10


Test Object 


Test Object Required?

Description

No


There was not requirement of object data argument


Input Data

 Input Data Required?

 Description 

SpecFileName

* It is of String type.

* It takes the name of the Spec (Objects) file.

* It is created once.

 

SpecFolderPath

* It is of String type.

*It takes the path(location) where SpecFile will be saved after creation.


Platform

* It is of String type.

* It takes the view(platform) on which a particular script has to be executed.

* Platform can be Mobile View or Desktop View.


Validate Baseline

* It is of Boolean type.

* By default it is False.

* If it is False, it will create the Spec(Objects) File.

* If it is True, it will compare the Specs(Objects) and will create a Visual QA Report.


Approximate Range

* It is of Integer type.

* It takes the approximate value upto which errors can be ignored.




Output Data

Condition

Output value

If the keyword passes successfully

True

if there is an error

False




Error conditions


Conditions

Error Message

Debug Information

If no object is provided

Argument Data Missing

 

Argument(s): (SpecFileName;

Platform;

SpecFolderPath; ValidateBaseline; Approximation

Range) is/are blank




7. LoadSeleniumJS

This keyword is used to load the OpKey Selenium-JS plugin at runtime which is to be used for the Test Execution. This keyword is generally used when you have a Test Case which has all Generic keywords along with few Selenium-JS keywords which are Selenium-JS specific. This keyword is doesn’t take any object or data input argument.

Example: 

Suppose there is a Test Case which has both mobile & web test steps. In such case, you need to load both plugins (OpKey Mobility & Selenium-JS plugins) at runtime so that they can be used for executing respective test steps, as required.

You need to add this keyword (LoadSeleniumJS) with a test step, just before stating the Web flows. Save the test case and then click on Run Now. It will take few moments to load the required plugins (as per the added test steps). There will be a popup message regarding the loaded plugins which will be used for executing the test case.


Test Object 


Test Object Required?

Description

No

This keyword does not require any Object input argument.


Input Data

 Input Data Required?

 Description 

No

This keyword does not require any Input data argument. 


Output Data

Condition

Output value

If the keyword passes successfully

True

if there is an error

False

Error conditions


Conditions

Error Message

Debug Information

When keyword “LoadSeleniumJS” is not added to the Test Step.

Oops! Seems like ‘SeleniumJS' is not added in your package or not installed with the agent. Kindly contact OpKey Support Team at support@opkey.com for assistance.

Oops! Seems like '‘SeleniumJS' is not added in your package or not installed with the agent. Kindly contact OpKey Support Team at support@opkey.com for assistance.

 

To learn how you can use these keywords in test scenarios, you can visit https://university.opkeylms.com and enroll in our Opkey series course.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article