Browser Actions | Zoho QEngine Help

Browser Actions

Perform essential browser actions with this list of tasks, enabling seamless interaction and automation for web testing and navigation.

Browser actions tasks include the following :
  1. Switch To
  2. Get URL
  3. Refresh
  4. Resize
  5. Browser navigation actions: Forward, Back & Close

1. Switch To  

The task performs the action of switching to a new window, new tab, or child iframes from their default window, tab or parent iframe.
 
Syntax
switchTo(<window_index>, <isFrame>);

 

 

Parameter

Data Type

Description

<window_index>

OBJECT

The URL or title displayed in the window of the target web


page

or the opened tabs. This can also be the index of the opened tabs, or, alternatively, the locator or index of the iframe within the opened webpage in a tab or window.

  1. If <isFrame> is true, the window_index considers the locator or index given as that of the iframe.

  2. If <isFrame> is false, the window_index considers the URL, title or index given as that of the tab or window.
Notes

Note:

In order to use the URL or the title displayed, use ("<URL>") or ("<title>"). And, to use the index of the tabs opened, where the first new tab's has an index "1" and so on.

 

In the case of iframe, you can either hard code the locators as ("<locator>"), or use the index of the iframe, where the first child has an index "1" and so on. Alternatively, you can also use recorded elements as, (ui.<locator>). Learn more about Elements
<isFrame>BOOLEAN

This takes a boolean logic value, either "TRUE" or "FALSE", which determines the window index given is iframe.

 

Syntax 

switchTo(<session_name>);


Parameter

Data Type

Description

<session_name>

OBJECT

The session names include:

  • window.DEFAULT

  • window.PARENTFRAME

  • window.PRIMARY

  • window.SECONDARY 

To switch between child iframes and the default webpage content. Use the following inputs:

  • window.DEFAULT: This allows you to switch from any level of nested child iframes back to the default content of the webpage, essentially returning to the starting point of the navigation.

  • window.PARENTFRAME: This allows you to switch from child iframes to the immediate parent iframe within the webpage. 

To switch between the default window and the new window, use the following inputs. Here, the primary window is the window that was opened first, and the newly opened window is referred to as the secondary window. 

 

NotesNote: This task allows only one new window to be accessed at a time.

  • window.PRIMARY: This refers to switching from the new window to the primary window. For example, if you need to navigate to a different URL, and perform actions independently of the default webpage. After, this task helps you to switch back to the primary page.

  • window.SECONDARY: This allows you to switch to the new window from your primary window. For example, if you require interactions with a webpage in your primary window while keeping the new session open. 

 

2. Get URL 

The task returns the current URL value of the webpage. For example, a user can fetch the URL to verify whether a webpage has been navigated to the expected URL.

 

Syntax 
<variable> = getURL();
 
Return Type
STRING

 

Parameter

Data Type

Description

<variable>

STRING

Variable that contains the URL value of the webpage.



Example: A user wants to test their e-commerce website. The following script searches for the product "casio vintage" and retrieves its current URL, compares it with the expected URL to validate that the user has reached the desired product page.
 
  1. openURL("https://www.zwatch.com","same window"); // Navigates to the URL. Learn more about openURL task
  2. sendKeys(ui.zwatch.field_keywords,["casio vintage", keys.ENTER]); // Searches for the product "casio vintage" in the search field. Learn more about the Send Keys task
  3. wait(3);
  4. current_URL = getURL();
  5. expected_URL = "https://www.zwatch.com/product-category/casio_vintage";
  6.  
  7. // Fetched URL being compared with the expected URL
  8.  
  9. if(current_URL == expected_URL)
  10. {
  11. info("URL verification successful. User has reached the correct product page.");
  12. }
  13. else
  14. {
  15. info("URL verification failed. User did not reach the expected product page.");
  16. }

 

where:

 

"https://www.zwatch.com"

URL of the website that needs to be opened.

"same window"

This represents that the URL needs to be opened in the same window.

ui.zwatch.field_keywords

The recorded element for the search input field.

"casio vintage"

The product searched in the input field.

[keys.ENTER]

The key sent to submit the input search field.

3

The time it waits for the product webpage to load

current_URL

The variable that captures the URL of the selected product.

expected_URL

The variable that stores the expected URL of the product.

"https://www.zwatch.com/product-category/casio_vintage"

The expected URL with which the product URL has to be compared.

"URL verification successful. User has reached the correct product page."

The message that has to be displayed, if the expected URL is the same as the product URL.

"URL verification failed. User did not reach the expected product page."

The message that has to be displayed, if the expected URL isn't the same as the product URL.

 

3.  Refresh  

The task refreshes the currently displayed webpage in a web browser.
 
Syntax 
refresh();
 
Example: A user wants to test the page loading time of their website. The following script refreshes the webpage for the product "Daytona", to ensure the page reloads correctly.
 
  1. openURL("https://www.zwatch.com","same window"); // Navigates to the URL. Learn more about openURL task
  2. click(ui.zwatch.zwatch_Daytona);
  3. refresh();

where:

 

"https://www.zwatch.com"

URL of the website that needs to be opened.

"same window"

This represents that the URL needs to be opened in the same window.

ui.zwatch.zwatch_Daytona

The recorded element of the product "Daytona", viewed from the e-commerce website.

4.  Resize  

The task resizes the browser window based on a predefined value or provided dimensions.
 
Syntax 
resize(<resize_input>);

 

Parameter

Data Type

Description

<resize_input>

STRING

The input determines how the window size of the webpage should be displayed.

 

The following are the three resize input:

  • FULLSCREEN: Maximize the web browser window to cover the entire screen, providing a full-screen view.

  • CUSTOMIZE: Tailor the window size to match your desired width and height for the browser window. It is measured in pixels.


NotesNote: In order to set the custom width and height for the window, use ("width:<int>,height:<int>").

  • MAXIMIZE: Enlarge the browser window to its default or pre-defined maximum dimensions.

 

 

Example 1: A user wants to test the resizing capability of an e-commerce website. The following script resizes the website window into the desired measurements.
 
  1. openURL("https://www.zwatch.com","same window"); // Navigates to the URL. Learn more about openURL task
  2. resize("width:800,height:600");
 
where:

 

"https://www.zwatch.com"

URL of the website that needs to be opened.

"same window"

This represents that the URL needs to be opened in the same window.

"width:800 , height:600"

The required measurements of the browser window in pixels.

 

Example 2: A user wants to test the resizing capability of an e-commerce website. The following script resizes the website window to fit the entire screen.
 
resize(window.FULLSCREEN);
 
Example 3: A user wants to test the resizing capability of a webpage on their e-commerce website. The following script resizes the website window to fit the predefined dimension of the display.
 
resize(window.MAXIMIZE);

5. Browser navigation actions: Forward, Back & Close

Efficiently navigate and manage browsing sessions with Forward, Back, and Close browser actions

 

5.1  Forward  

The task performs the action to move to the next page from the current page on the browser.


Syntax
forward();

5.2  Back  

The task performs the action to move back from the current webpage to the previous page on the browser.
 
Syntax 
back();

 

Example: A user wants to test browser navigation on their e-commerce website. The following script allows the user to navigate from the current webpage to the next page and back.
  1. openURL("https://zwatch.com","same window"); // Navigates to the URL. Learn more about openURL task
  2. wait(5); // The time it waits for the page to load
  3. click(ui.zwatch.terms); // Opens the terms and conditions page of the website. Learn more about Click task
  4. back();
  5. forward();

where:

"https://zwatch.com"

URL of the website that needs to be opened.

"same window"

This represents that the URL needs to be opened in the same window.

5

The time specified to wait for the URL to be opened.

ui.zwatch.terms

The recorded element for the terms and conditions webpage.

5.3 Close  

The task performs the action to close the current webpage on the browser.

 

Notes

Note: If there is only one open window in the browser, the task will not close it since it serves as the default window.

 

Syntax 

close();

Example: The following script navigates to the e-commerce website to view the product "Daytona". Closes that product to view another
  1. openURL("https://zwatch.com","same window"); // Navigates to the URL. Learn more about openURL task
  2. wait(3); // Wait specified for the e-commerce website. Learn more about wait task
  3. click(ui.zwatch.daytona); //Opens the page of product "Daytona" in a new window
  4. wait(3); // Wait specified for the webpage of the product "Daytona"
  5. close(); // Closes the product page
  6. openURL("https://zwatch.com/casio_vintage","new window"); // Navigate to the webpage of the product "casio vintage" in a new window.
  7. wait(3); // Wait specified for the webpage of the product "casio vintage"

where:
 

"https://zwatch.com"

URL of the website that needs to be opened.

"same window"

This represents that the URL needs to be opened in the same window.

3

The time it waits for the e-commerce website to load

ui.zwatch.daytona

The time it waits for the webpage of the product "Daytona" to load

3

The time it waits for the product webpage to load

"https://zwatch.com/casio_vintage"

URL of the webpage that needs to be opened.

"new window"

This represents that the URL needs to be opened in the same window.

3

The time it waits for the webpage of the product "casio vintage" to load