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

How to Launch Selenium WebDriver on different browsers

In this article, we will discuss on how we launch Selenium web driver in different browsers in Java. 

Before we go further with this, We need installing different jar files and making initial set up in Java, Please go through below link and other useful links to set up initial java project in eclipse with selenium jar files added to project build path.


Once we have configured eclipse and added required external libraries in the build path, we can start with a basic test in eclipse to solve following requirement: 
  It is required to perform following action on different browsers
  •         Open www.sagenda.net on browser specified by user
  •         Verify the title of the Page has Sagenda in the text.
  •      Close the browser.
Below is the self explanatory code in java using Selenium to perform the required job:


//These are the class libraries that needs to be imported
import java.io.File;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class Iteration {

//Define Webdriver object

 WebDriver driver;

//This is the main method to drive the test flow  

public static void main(String[] args) throws InterruptedException

//There are two part in the flow for which we created the required methods 

Iteration iter = new Iteration();

//a. Launching the required Browser

iter.LaunchBrowser("chrome");

//b. Providing the url of application and condition to verified in the test. Text in title in this example

iter.homePage("https://sagenda.net", "Sagenda");

}

//Function to launch required browser

public void LaunchBrowser (String strBrowser)

{

//based on the expected browser as provided in argument of method, we will launch the required browser

if (strBrowser.trim().toLowerCase().contentEquals("ie"))

{

//Launch IE browser://Pre-Conditions: Download IE driverServer.exe from the selenium download site and provide location where it is downloaded

 File file = new File("D:\\Selenium\\IEDriverServer.exe");

System.setProperty("webdriver.ie.driver", file.getAbsolutePath()); 

driver = new  InternetExplorerDriver();

}


else if (strBrowser.trim().toLowerCase().contentEquals("firefox"))

{

driver = new  FirefoxDriver();

}

else if (strBrowser.trim().toLowerCase().contentEquals("chrome"))

{

//Pre-Conditions: Download IE driverServer.exe from the selenium download site and provide location where it is downloaded

    System.setProperty("webdriver.chrome.driver", "d://chromedriver.exe");

   DesiredCapabilities capabilities = DesiredCapabilities.chrome();

   ChromeOptions options = new ChromeOptions();

   options.addArguments("test-type");

//Provide location where chrome is currently installed.  

    String Chrome_Path = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe";

   capabilities.setCapability("chrome.binary",Chrome_Path);

   capabilities.setCapability(ChromeOptions.CAPABILITY, options);

   driver = new ChromeDriver(capabilities);

}

else

{

//In case browser is not in above three , print below message 

System.out.println("This browser is currently not supported by me, Please select from IE/Firefox or chrome");

}

}

//Function to perform required action on the application

public void homePage(String url, String strTextinTitle)
{
try
{
//open the required url 
driver.get(url);
//once the url is launched, verify the title contains the required text.
//Note : In case we require exact match , we will use contentequals instead of contains
if (driver.getTitle().contains(strTextinTitle))
{
System.out.println("Title of the Page contains text :" + strTextinTitle );
}
else
{
System.out.println("Title of the Page does not contains text :" + strTextinTitle );
}
}
catch(Exception e)
{
System.out.println(e.getClass());
}
}
}

Understanding Union, Nested Queries and String function in SQL

In the previous article, we discuss on joins in SQL. In this post, we will start with nested query, and then understand how to use union, string function in SQL, and other topics that are useful for a tester to know.


   Problem 1: Let us start with a simple example. We need to know the name of user belonging to Organisations with org_code in Org003, Org004, Org005 using nested queries?


Answer: In this problem, we need to find the User_Name from User table but we need to create query to identify users which belongs to Organisations Org003, Org004, and Org005. Since User table is linked to organisation table by Org_Id. The Query should do something like. Select users from user table which belongs to Organisation having org_code as Org003, Org004, and Org005. This can be written in SQL using nested queries as follows:

Select User_Name from User where Org_Id in (Select Id from Organisation where Org_Code in (‘Org003’,‘Org004’,’Org005’)).


The above is an example of nested query, the same can be written using join as follows:

Select User_ from User us join Organisation org on us.Org_Id = org.Id where org.User_Code in(‘Org003’,‘Org004’,’Org005’)



Problem 2: Next problem is to find count of Organisation which pay salary to employees greater than 1000?


Answer: Salary is a field in User table and also we have org_Id in User table. And we are only concerned with the count of Organisation with salary greater than 1000. We can get the information from only User Table as:

Select count(distinct Org_Id) as OrganisationCount from User where Salary>1000;



Problem 3: Please explain the concept of union in SQL?


Answer: Union is used to combine data from multiple select queries in a record set. Number and data type of items in the select statement should match together.
e.g.: In above tables,
Select Id, Org_Name from Organisation Union Select Id, User_Name from User will fetch results

Select Id, IsActive from Organisation Union Select Id, User_Name from User will fail as the data type of items in the two select statements is not matching.

Select Id from Organisation Union Select Id, User_Name from User will fail as number of items in the two select statements is not matching.

So to union data from two or multiple select statements, the number of arguments, data type of argument, and order of arguments should match, else the union statement will fail.
Similar to Union is Union All. The difference between union and union All is while Union returns distinct record set ignoring duplicate record rows, Union All returns all the rows.


Problem 4: Suggest some useful string functions in SQL?


Answer: Some of useful SQL functions to work with string are:

UCASE() – Converts the string value into Upper Case.

Select UCASE(Org_Name) from Organisation

lcase() – Converts the string value into Lower Case.

Select lcase(Org_Name) from Organisation

Substring() – returns substring for column from start location and length as provided in argument. Similar to this in SQL Server, In Oracle we can Use Mid function.

Select substring(Org_Name,1,4) AS Org_4 from Organisation;

Use functions Substring and len to order by a specific part of a string

Select Org_Name from Organisation order by substring(Org_Name,len(Org_Name)-1,3)

Use + , we can concatenate multiple string and return the results.   


                                                                                                   

how to work with Multiple tables in SQL for tester– Understanding joins

We have gained knowledge on basic queries in SQL working with a single table in previous articles. Let us extend our knowledge working with multiple tables in SQL. Below are the tables, we will use in our examples.

This post will mainly discuss on concept of joins in SQL.In the next post, we will go further and discuss on nested queries, union, and other useful concepts on SQL.





Problem 1: From the above tables, provide Org_Name for each of the users in User Table?


Answer: First of all, we need to identify which information we need to extract from above table. We need Org_Name from Organisation table and Username from User Table.

Second Point is to identify the common attribute/column in two tables based on which we will create the relation between two tables. As in above tables, Org_Id is the foreign Key in table User which is mapped with Id in the Organisation table and is used to create a relation between the two tables.

We can use joins to get data the two tables. JOIN is used to combine rows from two or more tables, based on a common field between them. In this problem, we will use join or inner join or a equi – join to extract the required information


  •  INNER JOIN: Returns all rows when there is at least one match in BOTH tables. An Inner Join is same as Join or equi-join.

  •  Since we have make a match between Organisation and user table on Org_Id, we will create inner join or equi-join or simply join as shown in example below
    • Syntax - Join : Select * from Organisation a join User b on a.Id = b.Org_Id
    • Syntax - InnerJoin : Select * from Organisation a innerjoin User b on a.Id = b.Org_Id
    • Syntax – Equi-Join : Select * from Organisation a,User b where a.Id = b.Org_Id


Join and Inner Join are same thing and fetches the same results as Equi-Join between two tables.
Other than Inner Join or equi-Join, Other examples of joins are following:

  • LEFT JOIN: Return all rows from the left table, and the matched rows from the right table

    • Syntax- Left Join : Select * from Organisation a LEFT join User b on a.Id = b.Org_Id

  • RIGHT JOIN: Return all rows from the right table, and the matched rows from the left table

    • Syntax- Right Join : Select * from Organisation a Right join User b on a.Id = b.Org_Id

  • FULL JOIN: Return combined result of both LEFT and RIGHT joins.

    • Syntax- Full Join : Select * from Organisation a full outer join User b on a.Id = b.Org_Id

    In above problem, we will use an inner join and can use any syntax from Join, inner-join or equi-join.Since we require Org_Name and User_Name in Output, Instead of fetching all information using Select *, we will extract Org_Name from Organisation table and similarly User_Name from User table. Also we can use alias to giving meaningful name to column. The syntax will be :

    Select a.Org_Name as OrganisationName ,b.User_Name as User from Organisation a join User b on a.Id = b.Org_Id


    Problem 2: In the above tables, provide Org_Name, Salary and Designation for each of the user in User Table?

    Answer: In this example we need to create multiple join between tables. The query will be as follows. Try to understand the query with the concept explained in previous table.

    Select us.User_Name, org.Org_Name, us.Salary, des.staff_role from User us join Organisation org on us.Org_Id =org.Id join User_Designation usd on us.Id = usd.User_Id join Designation des on usd.Designation_Id = des.Id