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, 7 March 2021

Selenium

Automation Testing :

Automation testing enables the use of specialized tools to automate the execution of manually designed that cases without any human intervention. Automation testing tools can access the test data, controls the execution of tests and compares the actual result against the expected result. consequently, generating detailed test reports of the system under test.

Automation testing used automation tools to write and execute test cases, no manual involvement is necessary for executing an automated test suite. Testers prefer automation tools to write test scripts and test cases and then group into test suites.

Selenium -

Selenium is a suite of various tools that are used explicitly for automated web testing purposes. Its compositions have Selenium IDE, WebDriver, RC and Grid.

Components

Selenium is an automation testing tool, it is a package of several tools and it is a testing suite. Selenium suite has the following components.

Selenium IDE - Distributed as a Firefox plugin, Selenium IDE serves as a record and playback tool.

Selenium Grid - Allows distributing test execution across multiple platforms and environment's concurrently.

Selenium RC - A server that allows users to create test scripts in a desirable programming language. Selenium RC also permits executing test scripts across a diverse range of web browsers.

Selenium WebDriver - Communicated directly with the web browser in addition to using its native partibility to automate.

Difference in Selenium 2.0 and Selenium 3.0 from Selenium

Selenium 2.0 has consolidated selenium RC and WebDriver to make a single tool, while Selenium 3.0 is the latest version which has Beta 1 and Beta 2 updates.

WebDriver API's :

The list  of WebDriver API's which are used to automate browser includes :

  1. AndroidDriver
  2. ChromeDriver
  3. EventFiringWebDriver
  4. FireFoxDriver
  5. HtmlUnitDriver
  6. InternetExplorerDriver
  7. IPhoneDriver
  8. IPhoneSimulatorDriver
  9. RemoteWebDriver
Types Of Locators
A locator is a kind of address that offers a unique way of identifying a web element on the
webpage. Selenium has a range of locators to identify different elements of a webpage, namely :

  • ClassName
  • CSS Selector
  • DOM
  • ID
  • LinkText
  • Name
  • PartialLinkText
  • TagName
  • Xpath

XPath - XPath is a type of locator in selenium that is used to locate a web element based on its XML Path. XML denotes Extensible Markup Language, which is used for storing, Organizing and transporting arbitrary data. Much like HTML tags, XML stores data in a key value pair. Since HTML and XML both are markup languages, XPath can be used for locating HTML elements on a webpage. The underlying principle of XPath is traversing between several elements across the entire webpage and allowing them to find an element with the reference of some other element.

Single Slash - /  - The Single slash is used to create XPath with the absolute path. In absolute path, the created XPath will start selection from the document node or the start node.

Double Slash - // - The Double slash is used for creating XPath with the relative Path. In the relative path, the created XPath can start selection from anywhere within the entire web document.

Types of Waits :

Implicit Wait - Used for providing a default waiting time between each successive test step or command across the entire test script. Hence, the next test step or command will only execute when the set default waiting time, say 30 seconds, have passed since the execution completion of the previous test step or command. Can be applied to a particular instance or several instances.

Explicit Wait - Used for halting the execution until the occurrence of a particular condition or till the elapsing of the maximum time applied for a particular instance only.

Object Repository in Selenium

The term Object Repository refers to the collection of web elements that belong to AUT (Application Under Test) and their locator values. A corresponding locator value can be populated from the Object Repository whenever an element is required within the script..

Instead of hardcoding locators within the scripts, they are stored in a centralized location using Object Repository. Typically, the objects are stored in an excel sheet in selenium with acts as the Object.

Launching the Web Browsers  Using WebDriver

The syntax used for launching Google Chrome, Mozilla Firefox and Internet Explorer using WebDriver is respectively.

WebDriver driver=new FirefoxDriver();
WebDriver driver=new ChromeDriver();
WebDriver driver=new InternetExplorerDriver();

Finding An Elements on Web Browser

The WebDriver components of the selenium suite facilitates checking the visibility of web elements, which can be buttons, checkbox's, drop boxes, labels, radio buttons, etc... WebDriver allows doing so with the following three methods.

isDisplayed()
boolean buttonPresence = driver.FindElement(By.id("id")).isDisplayed();

isEnabled()
boolean searchIconEnabled = driver.findElement(By.id("id")).isEnabled();

isSelected()
boolean buttonSelected = driver.findElement(By.id("id")).isSelected();

Getting Text of web element :

In order to retrieve the inner text of a specified web element, selenium offers the get command. It returns a string value and doesn't require any parameters. Get command is one of the most widely used commands for verifying errors, messages etc.. 

Syntax :

String Text = driver.findElement(By.id("text")).getText();

Clicking An Hyperlink Using its Text :

The following command finds a specified element using the  linkText()  method and then clicks on that element to redirect the user to the corresponding webpage :

driver.findElement(By.linkText("Google")).click();

Another command that can be used for the same purpose is :

driver.findElement(By.partialLinkText("Goo")).click();

Difference between driver.close() and driver.quit() commands :

The close() method closes the currently accessed window by the WebDriver. Neither does the command requires any parameter nor does it returns any value.

The quit() method is used for closing down all the windows opened by the program. The quit() method doesn't require any parameter not does have any return value type.

Handling Web - based Pop-Ups

WebDriver allows handling web based popups via the Alert interface. The general syntax.

Alert alert = driver.switchTo().alert();
alert.accept();

Following are 4 methods are available for handling the web based popups namely :

String getText() - Returns text displayed on the alert box.
void accept() - Clicks on the "OK" button as soon as the pop up appears.
void dismiss() - Clicks on the 'Cancel' button as soon as the pop up appears.
void sendkeys(String stringToSend) - Inputs a specified string pattern in the alert box.

Navigation Commands -

Selenium supports a total of 4 navigation commands, listed as follows.

navigate().back() - Takes the user back to the previous webpages as per the web browser history.
Requires no parameters.

navigate().forward() - Navigates the user to the next webpage in the web browser history.
Requires no parameters.

navigate().refresh() - Reload all the web elements by refreshing the current webpage.
Requires no parameters.

navigate().to() - Lets the user launch a new web browser window and navigate to the specified URL given as a parameter.

Assertion

The role of Assertion in Selenium is to act as a verification point. It helps in verifying the state of the application that conforms to expectations.

There are three types of Assertion in Selenium which include the followings :
  1. Assert
  2. Verify
  3. WaitFor
Assert - Assert commands helps in checking if the element is on the page or not. The test will fail in case of missing the required element and will get terminated.

Verify - Verify commands helps in checking the element is on the page or not but will not terminate but will continue ahead on executing all the commands.

Exceptions

There are  different exceptions in Selenium WebDriver which includes.
  1. TimeoutException
  2. WebDriverException
  3. NoAlertPresentException 
  4. NoSuchElementException
  5. NoSuchWindowException