Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Selenium - Waiting using implicit, explicit and fluent classes for Objects

While automating with Selenium, we may require to pause the execution for specific duration or until a specific condition is satisfied. In this article, we will discuss on common scenario where we might like script to wait for few seconds or minutes. Before going to discuss different methods to wait in selenium Web driver, 

Let us discuss on scenarios where we require to pause the execution.
  • In case, we require to execute some other process between execution in the web browser. E.g. compressing some files to be uploaded from web.
  • In case of Page load, waiting until the new pages opens.
  • In case of availability or value displayed in controls, enable/disable of object in the Page or specific conditions is satisfied. 

Below are the different wait method used with selenium scripts for synchronization:

  •  Using Thread.sleep

  Thread. Sleep (10000) will make the script pause for 10 sec. Thread.sleep is used in script in case of execution outside of selenium code. For e.g.: Suppose in between performing browser operation, we need to execute some exe file which takes some time for execution to complete.

  • Using Implicit Wait 

 Implicit wait tells Webdriver to poll the DOM for a certain amount of time for object Identification and wait for availability of object, if not available at the instance of step execution. Once set, the implicit wait is set until the webdriver instance is closed.If the object is found below 50 sec , it will move to next step in the script.
          WebDriver driver = new  InternetExplorerDriver();
         driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);

  • Using Fluent Wait 

 Another wait which is very similar to Explicit Wait is fluentWait.
           FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver);
         //define the timeout – this is time the driver will wait for condition to be              satisfied.
        wait.withTimeout(10000, TimeUnit.MILLISECONDS);
        // define the poll time, here it will poll the DOM after 200 ms and will poll at fixed  interval until 10000 ms
       wait.pollingEvery(200, TimeUnit.MILLISECONDS);
       driver.get(url);
      // we define the wait time for a specific condition to be satisfied using                              wait.until(ExpectedConditions.condition) as explained below where the driver will wait until    the title of the Page contains “qaautomationqtp.blogspot.in”; We can also select from multiple conditions as shown in screenshot below:
 wait.until(ExpectedConditions.titleContains("qaautomationqtp.blogspot.in"));
 //We can also define to ignore specific types of exceptions using wait.ignoring (exception.class)e.g. :
  wait.ignoring(NoSuchElementException.class);


  • Using Explicit Wait   

WebdriverWait is an extension of fluent class but has functionality compared to fluent class for waiting for an object including pooling time, ignore settings to name a few.
         WebDriverWait wait = new WebDriverWait(driver, 50)
         wait.until(ExpectedConditions.elementToBeClickable(By.Id("dra_reference")));

WebdriverWait and fluent class can be considered as example of explicit wait as are defined explicitly for an element in the page, e.g. in wait.until(ExpectedConditions.elementToBeClickable(By.Id("dra_reference")));

It is explicitly waiting for the condition specific to object with Id as "dra_reference" to be clickable.
Implicit wait is not defined for specific object but checks for the existence of each element used and are implied until the driver instance is closed.

So if an object is not getting loaded before the script fails, give the object some time to load and let the script wait for object to get identified. If all the objects are slow, give an implicit wait for the driver that will wait for all the objects to be available or an explicit wait, waiting explicit for an objects condition. Hope this make some sense.


Tips to handle first hurdles using selenium webdriver on IE browser

Some useful tips while launching tips in launching browser:

          HurdleGet following error on launching the IE browser:
Exception in thread "main"org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information).


In case such error is displayed in the console, it is asking to set same protected mode setting for all the zones. This can be set as shown in screenshot below:



 Hurdle:  Some Websites especially in QA environment do not have proper certificates installed due to which we get an error Page with issue with security certificate. Once user clicks on Continue to this Website (not recommended), a pop up appears. How to handle the pop up window?



Usually in QA environment, on navigating a page is https://, certificate error is displayed. The links in the Page are identified easily using selenium, but the pop up is not handled properly using alerts as:
Alert alert = driver.switchTo().alert();
alert.accept();

Alerts are used to handle javascript alerts that pop up in between.
Alerts can be used to accept a pop up, dismiss a pop up,getText(),SendKeys.

I tried to handle the pop up for res://ieframe.dll/ using alerts, but it did not work out. On further trying, I find a simple solution to the solution. The solution to the problem is to add res://ieframe.dll/ to the trusted sites or local intranet.

       Hurdle: Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Browser zoom level was set to 150%. It should be set to 100% (WARNING: The server did not provide any stacktrace information


This error occurs in case the zoom level is set different from 100% zoom level.

So to consolidate, before running any test in IE, we should ensure :
      a.      Protected mode is set same for all the internet zones and
      b.      Zoom level is set as 100% in the IE browser.

     How do we maximize the browser on launching the browser?


Using  below code , we can maximise the browser:

WebDriver driver;
File file = new File("D:\\Selenium\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath()); 
driver = new  InternetExplorerDriver();
driver.manage().window().maximize();

Creating first test in Soap UI/Ready API


In this article, We will discuss on how to create a test in SOAP UI. Before starting, we need to discuss what SOAP UI is.  SOAP UI is web service testing application for SOA and Rest. Below is the step by step process and each step is described in detail to as to enable user able to create first tests in SOAP UI/ Ready API. We will discuss on following in this article                                                   

1.   Creating first project in SOAP UI

2.   Creating a test suite.

3.   Adding test case in the test suite

4.   Adding test steps to test case.

5.   Executing the test case.



1.   Creating first project in SOAP UI


a.    A new project can be created using menu Option File>Create a new Project or pressing Ctrl + shift + N.


b.   A new project Window appears to create a new project. Select the required option. Since in this example, we are creating a project from WSDL file, I have selected the option to import project from a WSDL definition (SOAP). Click on Ok.

c.   In New SOAP Project, Provide the URL /Path of WSDL and Name of the Project

d.   User can opt for creating sample request for operations in the WSDL and creation of a test suite for the Project.


2.   Useful  Setup information at Project level


a.   There are some project specific properties. Together with Project Properties, we can define custom properties that are used across test suites or requests in the test.
b.   We can define the endpoints and custom properties of different environment at project in case we have different environment on which we need to test the application.

c.   We can define the users in WSS-configuration to use the username/Password to access operations in the soap.


3.   Once a project is created, we can create a test suite in the Project.  A test suite contains a collection of test cases. Each test case consists further of test step. There can be multiple test suites in the Project. We can provide custom properties at the test suite similar to project and can set the environment to run the test suite.

4.   Inside a test suite are test cases. At test case level we define the test steps which are created to be executed. Below are some of the useful test steps in a test case:


a.   Data Source – To create a data driven test in soap UI, We create a data source.
b.   Data Source Loop – To loop through the steps in the test case from target step.
c.   Properties – Sets properties to be used in the test.
d.   Groovy Script – Groovy script to generate output from a script
e.   SOAP request – Adding a soap request in the test
f.    Property transfer – Transferring property value from the response to  data sink
g.   Data Sink – transferring value from test to external file.
h.   Delay – Delaying the execution by millisecond

5.   In Soap request, we can define assertions in the test to validate if the response from the request is valid and as expected.