Miscellaneous Keywords of Selenium Library in Robot Framework

The Miscellaneous keywords are enhanced keywords, which contain the group of keywords reduced to a single keyword. The miscellaneous keywords are mostly used in the case of End to End Automation Framework.

In the case of Flight application, I have created a keyword called Login to Flight Application, which is nothing but a miscellaneous keyword.

Installation of Selenium Library

Different Types of Miscellaneous Keywords of Selenium Library in Robot Framework

Selenium contains Some of the Miscellaneous Keywords such as:

Assign an ID to an Element

Sometimes there are Xpath expressions that are very complicated, and the requirement is we need to use these XPath expressions again and again, so in that case, we use this keyword Assign an ID to an Element.

This provides temporary ID to an element and required when Locator is complicated and/or slow XPath expression and it is needed multiple times.

The Assign an ID to an element has two parameters such as :

  • Locator
  • ID
Capture Page Screenshot

Takes a screenshot of the current page and embeds it into the log file.

The Following Example demonstrates the Keywords, capturing the page screenshot and Assign an ID to an Element.

Open the Ride Editor and create a new test case as Assign ID to an Element

create-test-case-assign-id-to-an-element

Open the ngendigital page and select the Table Example, in that select the UK and try to find the Xpath for the same.

select-uk-and-inspect-element-in-table-example

finding-xpath-for-uk

The identified element is a unique element and hence write the test case for the same.

test-case-for-assign-id-to-an-element-in-table-exmple

If you observe the above test case, I have assigned a temporary element to pm. Now, select the test case and run, once it starts executing, it will open the Ngendigital/practice page and verifies the table example whether it is having the UK in the table or not and closes the browser.

If you open the test report, you will see that It has assigning temporary id 'pm' to an element.

test-report-of-assign-id-to-an-element

Close All Browsers

Closes all the open browsers and resets the browser cache. Instead of mentioning the close browser every time in the test case, you can mention it inside the teardown to make sure all browsers are closed.

test-teardown-keyword-robot-framework

Current Frame Should Contain

Verifies that the current frame contains the text.

Element Attribute Value Should Be

Verifies element identified by locator contains expected attribute value. Open the ngendigital practice page and inspect the element in the checkbox example

inspect-checkbox-example

We have three input types with the same name and different values, write the Xpath and find the unique element.

xpath-for-bmw

The identified element is a unique element and hence write the test case by using the keyword Element Attribute Value Should Be.

Open the Ride editor and create a new test case as Miscellaneous

creating-new-test-case-miscellaneous

Now, write the test case as shown below

test-case-for-bmw-robot-framework

Here I am going to check whether it is having the attribute name and the value associated with it. Select the test case and run, Once the test case starts executing the ngendigital page will open and verifies whether the current frame contains text or not and then checks for the attribute value.

Open the test report

verifies-for-text-and-attribute-value-robot-framework

Element Should Be Disabled

Verifies that the element identified with the locator is disabled.

Open the cineplex page and on the right side, there is a search option By Theater or by Movie, If you observe that the Type or select movie and Select Date are disabled. To verify that just right-click on Type or Select Movie and inspect the element.

inspect-type-or-select-movie

In the Dom, you can see the element select movie is disabled

type-select-movie-is-disabled

Now, Open the Ride editor and create a new test case as Disabled Element

new-test-case-for-disable-element

And write the test case for the same

test-case-for-disabling-tyoe-and-select-movie-robot-framework

Now, select the test case and Run, Once it starts executing, the editor checks for whether the element identified by the locator is disabled or not.

Open the Log report:

test-report-for-disabling-element-robot-framework

Get Element Count

Gets the count of the element specified by the locator. Useful for the assertion of the number of matching elements.

Open the Ride Editor and create a new test case as Count Element

test-case-for-count-element

Open the ngendigital page and select the checkbox example and inspect the element, we found that there are three values associated with the input type. We have to verify how many checkboxes are associated with the checkbox manually.

Write the XPath for the car element as //input[@name='car']

xpath-for-the-car-element

Now, write the test case as shown below

count-element-complete-test-case

Select the test case and run, once completes executing the test case, it will open the ngendigital page and verifies the number of elements associated with the checkbox.

Now, open the log report, you can see ${var}=3, that means there are three elements associated with the checkbox.

log-report-for-count-element-1

Go To

Navigates to the specified URL

Go Back

Navigates back to the previous URL

The following test case demonstrates the Go To and Go Back keywords.

Go to RideEditor and create a test case as shown below:

complete-test-case-for-go-to-and-go-back

Once you run the test case, the editor will open the specified URL ngendigital page and then opens the cineplex browser and go back to the base URL.

The Log Report is:

verifies-for-text-and-attribute-value-robot-framework

Location Should be

Sometimes the URL we specified and the URL which will open is exactly different, So to overcome this problem we can use Location should be a keyword. This keyword requires a URL and if the specified URL is different from the actual window, we can customize a message.

The URL argument contains the exact URL that should exist in the browser.

Log Location

Whatever the URL opens on the webpage it will return to us.

Log source

Logs and returns the HTML source of the current page or frame. The log-level argument defines the used log level. Valid log levels are WARN, INFO (default), DEBUG, TRACE and NONE (no logging).

Log Title

Logs and returns the title of the current page.

Register Keyword To Run On Failure

If any test case got failed then by default the selenium will take the screenshot of that page. Possible to use any available keyword, including user keywords or keywords from other libraries, but the keyword must not take any arguments, we can use NONE keyword too.

Creating a new test case as URL Verify and write the test case as shown below

creating-url-verify-test-case

testcase-of-url-verify-location-should-be

The continued part of the test case is as below

url-verify-continued-part

Once you run the test case, it will open the ngendigital page and then closes the browser and verifies the browser, if the URL is not the same then switched to the Gmail page and closes the browser. If you open the log report you can see everything in detail.

log-report-of-url-verify

User Defined Keywords Using Python in Robot Framework

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Subscribe to See Videos

Subscribe to my Youtube channel for new videos : Subscribe Now