Tricentis Tosca 16.0 Released on Feb-2023 ----- UFT has been upgraded from UFT 15.0.1 to UFT One 15.0.2, Beginning at November 2020.

Sunday 9 May 2021

WebTable Methods

 

Method ActivateCellDouble-clicks the specified cell in a table.

Syntax- object.ActivateCell (Row, Column)
Common Method CaptureBitmapSaves a screen capture of the object as a .png or .bmp image using the specified file name.
Syntax- 
Common Method CheckChecks whether the actual value of an item matches the expected value.
Common Method CheckPropertyChecks whether the actual value of the specified object property matches the specified expected value within the specified timeout.
Common Method ChildObjectsReturns the collection of child objects contained within the object.
Common Method GetAllROProperties

Returns the collection of properties and current values from the object in the application.

Method ClickCellEmulates a click on the specified cell in a table.
Method ColumnCountRetrieves the number of columns in the table.
Method DeselectColumnClears the selection of the specified column.
Method DeselectRowClears the selection of the specified row.
Method DeselectRowsRangeClears the selection of the specified rows in the table.
Method ExtendColumnSelects an additional column in the table.
Method ExtendRowSelects an additional row in the table.
Method ExtendRowsRangeAdds the specified range of rows to the selected rows in the table.
Method FindAllRowsByCellContentRetrieves all rows of all cells in the given column whose content matches the specified data.
Method FindRowByCellContentRetrieves the first row of the cell in the given column whose content matches the specified data.
Method GetCellDataReturns the data contained in the specified cell.

Method GetCellDataEx

Returns a cell's content from a row with specific content in another cell.

Method GetCellLengthRetrieves the maximum length of the cell.
Common Method GetROPropertyReturns the current value of the description property from the object in the application.
Common Method GetTOPropertiesReturns the collection of properties and values used to identify the object.
Common Method GetTOPropertyReturns the value of the specified description property from the test object description.
Common Method HighlightHighlights the object in the application.
Method InputRecords an Input statement each time new or modified table cell data is sent to the SAP server.
Method IsCellEditableChecks whether the cell is editable.
Method OpenPossibleEntriesOpens the list of possible entries for a table.
Common Method OutputRetrieves the current value of an item and stores it in a specified location.
Method PressSettingsButtonPresses the table setting button.
Common Method RefreshObjectInstructs UFT One to re-identify the object in the application the next time a step refers to this object.
Method RowCountReturns the number of rows in the table.
Method SelectAllColumnsSelects all columns in the table.
Method SelectCellSelects the specified cell in a table.
Method SelectColumnSelects the specified column in the table.
Method SelectRowSelects the specified row in the table.
Method SelectRowsRangeSelects the specified range of rows in the table.
Method SetCellDataSets the cell contents with the specified data.
Common Method SetTOPropertySets the value of the specified description property in the test object description.
Common Method ToStringReturns a string that represents the test object.
Method ValidRowIndicates whether or not the specified row is a valid row for the table.
Common Method WaitPropertyWaits until the specified object property achieves the specified value or exceeds the specified timeout before continuing to the next step.

Saturday 8 May 2021

Selenium WebDriver Commands

Selenium WebDriver commands can be classified as Get commands, Navigation commands, WebElement commands, Action commands, and Result commands.

Get Commands - Get commands are the most commonly used commands to perform the basic operations of WebDriver such as opening a browser, performing a few tasks, and then closing the browser.

Syntax: get(String arg) : void

The get() method takes a string URL as a parameter and returns nothing.

Syntax:

WebDriver Get command










Example

driver.get("https://www.google.com"); 

// Or It can be also written as 

String URL = "https://www.scientecheasy.com"; 

driver.get(URL);

Get Current URL -   The getCurrentURL() method takes nothing as a parameter and returns URL of the web page currently loaded in the browser.

getCurrentUrl() : String

Syntax:
driver.getCurrentUrl();

Example
driver.getCurrentUrl(); 
// The above code can be also written as 
String currentUrl = driver.getCurrentUrl(); 
// Since the return type of getCurrentUrl() method is String. So, we will store it using variable currentUrl with String data type.

Get Title Command - The getTitle() method takes nothing as a parameter and returns the page title of the currently loaded web page. If the web page has no title, it will return a null String.

getTitle() : String
Syntax:
driver.getTitle();
Example
driver.getTitle(); 
// The above code can also be written as 
String title = driver.getTitle(); // Return type of getTitle is String.

Get Page Source Command-  The getPageSource() method accepts nothing as a parameter and returns the source code of the current web page. This method is used to get the page source code of the currently loaded web page.
Syntax:
driver.getPageSource();
Example
driver.getPageSource(); 
// Or 
String pageSource = driver.getPageSource();
// Since return type of the this method is String. Therefore, the output must be stored in a variable with datatype String.

Get Text Command The getText() method accepts nothing as a parameter and returns a string value. This method is used to retrieve the inner text of the specified element.
getText() : String
Syntax:
driver.findElement(By.locatorName(“Specified Element”)).getText();
Example
String text = driver.findElement(By.id("India")).getText(); // id is name of locator. India is a specified element. 
System.out.println(text); 
// The above code can also be written as 
WebElement element=driver.findElement(By.id("India")); 
String text=element.getText(); // Return type of getText method is String. 
System.out.println("Inner Text: " +text);

Get Tag Name Command- The getTagName() method takes nothing as a parameter and returns a String value. This method is used to get the tagName of the WebElement returned by the findElement(By) method.
getTagName() : String
Syntax:
element.getTagName(); // Here. element is a variable whose return type is WebElement.
Example -
String tagName = driver.findElement(By.id("DownloadButton")).getTagName(); 
// or 
WebElement element = driver.findElement(By.id("DownloadButton")); 
String tagName = element.getTagName(); 
System.out.println(tagName);

Get CSS Value CommandThe getCssValue() method accepts nothing as a parameter and returns a String value. This method is used to fetch the value of the CSS property of the given web element when it is invoked.
getCssValue() : String
Syntax:
element.getCssValue();

Get Attribute Command  The getAttribute() method takes the String as a parameter and returns a String value. It is used to fetch or get the value of the attribute of the WebElement.
getAttribute(String Name) : String
Syntax:
element.getAttribute();
Example
WebElement element = driver.findElement(By.id("DownloadButton")); 
String attributeValue = element.getAttribute("id"); //This will return "DownloadButton". 
System.out.println(attributeValue);

Get Size Command-  The getSize() method does not accept any parameter but returns the size of the element on the page. This method is used to fetch the width and height of the rendered element.
getSize() : int
Syntax:
element.getSize();
Example - 
WebElement element = driver.findElement(By.id("DownloadButton")); 
Dimension elementSize = element.getSize(); 
System.out.println(“Height :” + elementSize.height + ”Width : "+ elementSize.width);

Close CommandThe close method takes nothing as a parameter and returns nothing. This method is used to close only the browser window that web driver is currently controlling.
close() : void
Syntax:
driver.close();

Quit Command The quit() method accepts nothing as a parameter and returns nothing. This method is used to close all windows opened by WebDriver.
quit() : void
Syntax:
driver.quit();



Saturday 1 May 2021

Basic steps of Selenium testing and its widely used commands via a practical application.

Basic steps of Selenium testing and its widely used commands via a practical application.

Selenium testing can be divided into the following seven basic elements:

Creating an instance of a web driver: This is the first step for all the usages of a Selenium webdriver API. An instance of a webdriver interface is created using a constructor of a particular browser. This webdriver instance is used to invoke methods and to access other interfaces. Following are the most commonly used commands for initializing a web driver:


    Firefox:
    WebDriver driver = new FirefoxDriver();
    
    Chrome:
    WebDriver driver = new ChromeDriver(); 
    
    Safari Driver:
    WebDriver driver = new SafariDriver(); 
    
    Internet Explorer: 
    WebDriver driver = new InternetExplorerDriver(); 


Navigating to a webpage:
 The second step after initializing an instance of a webdriver, to navigate to a particular webpage we want to test. Following are the most commonly used commands for webpage navigation:

    Navigate to URL: 
    driver.get(“https://www.interviewbit.com”) 
    driver.navigateo.to(“https://www.interviewbit.com”) 
    
    Refresh page:
    driver.navigate().refresh()
    
    Navigate forward in browser history:
    driver.navigate().forward()
    
    Navigate backward in browser history:
    driver.navigate().backward()
    

Locating an HTML element on the webpage
:
 To interact with a web element and perform actions on it like clicking a button or entering text, we first need to locate the desired elements such as the button or the textbox on the web page. Following are the most commonly used commands for web element navigation:

    Locating by ID:
    driver.findElement(By.id("q")).sendKeys("Selenium 3");
    
    Location by Name:
    driver.findElement(By.name("q")).sendKeys ("Selenium 3");
    
    Location by Xpath:
    driver.findElement(By.xpath("//input[@id==’q’])).sendKeys("Selenium 3");
    
    Locating Hyperlinks by Link Text:
    driver.FindElement(By.LinkText("edit this page")).Click();
    
    Locating by ClassName
    driver.findElement(By.className("profileheader"));
    
    Locating by TagName
    driver.findElement(By.tagName("select')).click();
    
    Locating by LinkText
    driver.findElement(By.linkText("NextPage")).click();
    
    Locating by PartialLinkText
    driverlindElement(By.partialLinkText(" NextP")).click();
    

Performing actions on an HTML element: Once we have located the HTML element, the next step is interacting with it. Following are the most commonly used commands for performing actions on HTML element:

    Entering a username
    usernameElement.sendKeys("InterviewBit");
    
    Entering a password
    passwordElement.sendKeys("Raw");
    
    Submitting a text input element
    passwordElement.submit(); 
    
    Submitting a form element:
    formElement.submit();  
    

Anticipating browser response from the action
:
 Once an action is performed, anticipating a response from the browser to test comes under this step. It takes a second or two for the action to reach the browser, and hence wait is often required for this step. There are two main types of wait conditions:
    • Implicit Wait: It sets a fixed, definite time for all the webdriver interactions. It’s slightly unreliable as web driver response times are usually unpredictable.

      Eg: driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    • Explicit Wait: This type of wait condition sets an expected condition to occur on the web page or a maximum wait time for all the webdriver interactions.
    • Eg: WebElement messageElement = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("loginResponse")) );

Running tests and recording their results using a test framework
:
 in this step, we run tests in an automated test script to evaluate an application's function and performance. Various test frameworks are used for this step, such as:
    • JUnit for Java
    • NUnit for C#
    • Unittest or Pyunit for Python
    • RUnit for Ruby

    Most frameworks use some sort of asset statement to verify their test results from the expected results.

    Eg: assertEquals (expectedMessage, actualMessage);

Concluding a test
:
In this step, we conclude a test by invoking a quit method on the driver variable. This step closes all the webpages, quits the WebDriver server, and releases the driver.
    Eg: driver.quit();

The following is an example of an app that covers all the steps mentioned above:

import org.openqa.selenium.By,
import org.openqa.selenium.WebElement, 

import org.openqa.selenium.support.ni.ExpectedConditiof, 
import org.openqa.selenium.support.ni.WebOriverWait,

import org.junit.Assert;

public class Example {

public static void main(String[] args) {

// Creating a driver instance
WebDriver driver = new FirefoxDriver(), 

// Navigate to a web page
­driver.get("http://www.foo.com");

// Enter text to submit the form
WebElement usernameElement = driver.findElement( By.name("username"));
WebElement passwordElement = driver.findElement(By.name(”password"));
WebElement formElement = driver.findElement(By.id(”loginForm")); 

usernameElement.sendKeys("Scaler Academy");
passwordElement.sendKeys("Raw"); 

formElement.submit();      // submit by form element 


//Putting an explicit wait
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement messageElement = wait.until(
       ExpectedConditions.presenceofElementLocated(By.id(”loginResponse")) 
       ) ; 

// Run a test
String message = messageElement.getrept();
String successMsg = "Welcome to foo. You logged in successfully.”;
Assert.assertEquals (message, successMsg); 

// Conclude a test
driver.quit();
}
}

Demonstrating usage of Selenium through a test application.

Demonstrating usage of Selenium through a test application.

The following prerequisites to run a demo Selenium test script:

  • Java SDK in our respective Operating System.
  • Java-based IDE such as Eclipse or IntelliJ.
  • Selenium Web Driver to be added as a dependency to Java IDE.
package DemoTest;
 
import org.openqa.selenium.firefox.FirefoxDriver;
 
import org.openqa.selenium.WebDriver;
 
 
public class MyFirstTestClass {
 
 
  public static void main(String[] args) throws InterruptedException {
 
//It sets the system property to the given value.
System.setProperty("webdriver.gecko.driver","D:\\Softwares\\geckodriver.exe”);        
 
WebDriver driver = new FirefoxDriver();
 
          driver.get("https://www.google.com/");
 
          //Launch website in the browser 
          driver.manage().window().maximize();
 
  //The sleep pauses the execution of the thread for 5000 ms.
          Thread.sleep(5000);
 
          driver.quit();
 
  }
 
}

Once we run the above script in a Java IDE, we’ll get the following execution logs displayed in your IDE window.