SDLC and STLC, A must know for every project.

SOFTWARE DEVELOPMENT LIFE CYCLE:-

SDLC is the process followed by every organization for a software project. It consists of a detailed plan describing how to develop, maintain, replace and alter or enhance specific software. The life cycle defines a methodology for improving the quality of software and the overall development process.

Lets see the pictorial view and go deeper for each of the stages.

1

Stage-1: Planning & Requirement Analysis:

Requirement is the first step to every project we start may it be a mobile or a web application & Planning for it in the most optimized way. The planning for the requirements are done by the senior professionals keeping the customer needs, surveys and with the help of the experts in the industry.

Planning for the assurance of the product, the requirements and pre-identification of the risks so that every work output is feasible and optimum. Here in this stage the analysis of the product requirements is done.

Stage-2:Defining Requirements:

After the analysis of all the requirements for the product, the proper documentation is done for the each requirement by defining them based on why and how (in most optimum way) the requirements are to be taken care of. This is done through SRS (Software Requirement Specification) documents that would contain all the requirements to be designed for the development of the product. SRS is the fundamental and very important document as it is required in every stage of the product development.

Stage-3:Designing the Product architecture:

The architecture is done based on the SRS document that is made from the previous stage. Normally not only one design for the product is made/developed, more than one is developed and specified in the DDS(Design Document Specification). Then, this DDS is reviewed by all the stakeholders and keeping in mind the risk assessment, product robustness, design modularity and the most optimum design or architecture is chosen and before that every details of the proposed or chosen architecture’s internal structure should be mentioned in the DDS.

Stage-4:Building and Developing the Product:

Here in this stage, the actual work/development & product building starts. The coding starts by the developers working on the project based on the DDS prepared in the previous stage. Here the coding guidelines are followed that is the basic and most important as that is the first thing to be seen if the project transfers to other developers incase. The programming language is followed based on the software being developed.

Stage-5:Testing the Product:

This is another important part of SDLC models. This stage refers to the testing of the staging of the product where the defects of the products are reported by the testing group, then featured to the developers who fix the errors reported and again retested until and unless the product finally reaches the standards that is defined in the SRS.

Stage-6:Deployment of the product:

Once the development of the product is done after the series of coding and testing is done and the final outcome is satisfactory according to the specification provided in the SRS, & based on the feedback from the customers, then the deployment is done and the application goes live for the users too.

 

SOFTWARE TESTING LIFE CYCLE:

As discussed above about the SDLC that was related to development, but as we know development is incomplete without testing, unless and until it is confirmed that the development is free of bugs or Issues, it cannot be released to the customers. Similar to the development, testing also has its life cycle. Now lets discuss about the Software Testing Life Cycle. This involves a series of activities that are required to certify a product before delivery.

The different stages are listed and briefed below:-

2

Stage-1:Requirement Analysis:

In this phase as the name suggests, the test team gathers and studies the information required from a testing point of view. The QA team discusses with the development team, the clients and other stakeholders to gather more knowledge on the product to be tested. Requirement are of two types that is Functional(what is S/W must do as based on the SRS) and Non Functional(testing the performance of the product). If in case the requirements or the flow of the application is not understood by the test team, they consult to the respective Business Logic analysts, Team Leads/Developers, to get the thorough knowledge on the application. Also, here the priorities are kept in mind if there are any required by the client.

Stage-2:Test Planning:

As the name defines itself, that it is the stage where the testers plan on the process they would follow for testing the product. This is very important stage as this would decide the estimate of the completion of the testing process as if done in a planned and optimized manner, this would lead to a good product development. Test tools selection plays a vital role here & also the Development team is given the estimation by which the testing process would end. The test team also provides the estimation of cost along with the time estimation.

Stage-3:Test Development:

This stage can also be termed as Test Design, where the test case is prepared. Where according to the planning done in the previous stage, the test design is made on basis of which the work would get started. This is the phase of STLC where testing team write down the detailed test cases. Then these test cases are reviewed by the reviewer and then is approved. The Requirement Traceability Matrix is prepared, which is an industry-accepted format/rule for tracking requirements where each test case is mapped with the requirement specified in the SRS (Requirement phase).

Stage-4:Test Execution:

Once the unit testing is done by the developers and test team gets the latest build. Here in this stage the test case prepared and reviewed, is executed by the tester and the test results are the outcome here, these test results are captured, reviewed again and filed to the developers to work on the Issues (if any), else a green signal for the developers to continue with new module as the previous work has passed the testing process. Hence, here we get to know that “Testing is an iterative process, that is once the defect/issue is raised by the tester and then fixed by the developers, testing is again done to ensure the status of the defect”.

Stage-5:Bug Tracking & Reporting:

As mentioned above based on the test results, the tester files or reports the bugs/Issues found from thorough testing for the developers, so that they can go through and fix the bugs as soon as possible, so as to continue with further development. The developers once gets notified of the Issue/bugs raised by the tester, start fixing and implementing them. Not only issues, the testers also file suggestions if they think are required. The developers work on these points and then , the testers test and assure the defects have been fixed and suggestions have been looked into and then push it to the final testing.

Stage-6:Final Testing:

In this final stage the product is tested(functional & non functional) for the final time with every tit & bit taking into consideration, the quality of the product before letting it off to the customers. Here apart from functional, non functional testing are taken into consideration. Then the final test and execution documentation is made.

Thus on a final note,

  • The SDLC & STLC are both interdependent, or so to be called STLC is the SUBSET for the SET of SDLC.
  • STLC cannot run independently as they are confined to testing module only, whereas the SDLC is a vast model having wider area for executions and implementations.
  • SDLC is not alone enough as STLC is an important part of the product development as without Testing the product cannot be released for delivery.

Thus for an efficient, optimized & best quality product, both SDLC and STLC are equally important in their aspects.

Web driver script for Gmail Login Test with valid and invalid test data.

In this article I will be writing script for gmail login using various test Cases.

Test scenario-

CASE – 1 [ Enter Correct user Name and Password ]

  • Check whether Email field exist or not, if exit then write correct email Id
  • Check whether Password field exist or not,if exit then write correct password
  • Check if sign-in button exist or not, if exist then click on sign-in.
  • Check if login was proper or not by comparing the text of Primary tab.
  • Click on the account link containing Sign-Out button and click on Sign-Out button.
  • Check whether Signout was proper or not.

CASE – 2 [ Both Email and Password Fields are blank. ]

  • In the Email field & Password field, don’t  enter any data.
  •  click on sign-in.

CASE – 3 [ Email field is filled and Password field is blank. ]

  • Enter correct Email Id in Email field.
  • In the Password field, don’t  enter any data.
  •  click on sign-in.

CASE – 4 [ Email field is blank and Password field is filled ]

  • Enter correct Password in Password field.
  • In the Email field, don’t  enter any data.
  •  click on sign-in.

CASE – 5 [ Email and Password are entered wrong ]

  • Enter wrong Email Id in Email field.
  • Enter wrong Password in password field.
  •  click on sign-in.

CASE – 6 [ Email is wrong and Password is correct ]

  • Enter Incorrect Email in Email field.
  • Enter correct Password in Password field.
  •  click on sign-in.

CASE – 7 [ Email is correct and Password is wrong ]

  • Enter correct Email Id in Email field.
  • Enter incorrect Password in Password field.
  •  click on sign-in.
  • Close the browser.

Now we will write the code as below.

package package1;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Gmail {
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    // Initialize WebDriver
    WebDriver driver = new FirefoxDriver();

    // Maximize Window
   driver.manage().window().maximize();
  
    // Wait For Page To Load
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

   //Navigate to Google webstites
   driver.get("https://www.gmail.com");

 
/*CASE- 1. Both User name and Password are entered correctly. 
Check whether Email field exists or not */
    try
        {
          WebElement a1 = driver.findElement(By.xpath("//*[@id='Email']"));
          System.out.println("---------Email field exists --------------\n-----------------------");
          a1.sendKeys("ENTER CORRECT MAIL ID");
         }
    catch(Throwable e)
         {
         System.out.println("Email field not found: " + e.getMessage());
         }

    //Check whether Password field exists or not
     try
        {
	 WebElement password = driver.findElement(By.xpath("//*[@id='Passwd']"));
         System.out.println("----------Password field exits ------------\n-----------------------");
         password.sendKeys("ENTER CORRECT PASSWORD");
        }
    catch(Throwable e)
        {
	 System.out.println("Password field not found: " + e.getMessage());
        }

     //Asserting the Sign In button exists or not and clicking it
    try
       {
	WebElement button = driver.findElement(By.id("signIn"));
        System.out.println("-------Sign In button exists----------\n-----------------------");
       //To uncheck the "Check sign in" checkbox
       WebElement check_stay_sign_in = driver.findElement(By.xpath("//*[@id='PersistentCookie']"));
        check_stay_sign_in.click();   
	button.click();
        }
    catch(Throwable e)
        {
	System.out.println("Sign In button not found: "+ e.getMessage());
        }
    //Check if login was proper or not
    try
        {
	WebElement GmailText = driver.findElement(By.xpath("//*[@id=':36']"));
        String text = GmailText.getText();
        if(text.equals("Primary"))
       {
	System.out.println("----------Sucessful Login -------\n-----------------------");
       }else
       {
	System.out.println("----------Login Failure ----------\n-----------------------");
	}
       }
     catch(Throwable e)
        {
	 System.out.println("Inbox link not found: "+e.getMessage());
        }
    //===
    //Asserting and click on the Account link which contain Signout button.
     try
        {
	WebElement person = driver.findElement(By.xpath("//*[@id='gb']/div[1]/div[1]/div[2]/div[5]/div[1]/a/span"));
        System.out.println("--------The Account link containing Signout button exists ---------\n-----------------------");
	person.click();
       }
    catch(Throwable e)
       {
	System.out.println("Link for the drop-down not found: "+e.getMessage());
        }


    //Asserting and clicking on the Signout button.
    try
       {	
	WebElement signout = driver.findElement(By.xpath("//*[@id='gb_71']"));
        System.out.println("--------Sign out button exists  ---------\n-----------------------");
	signout.click();
        }
    catch(Throwable e)
        {
	System.out.println("Sign out button not found: "+e.getMessage());
        }

    //Check whether Signout was proper or not.
    try
       {	
       WebElement GmailText = driver.findElement(By.xpath("//div[@class = 'banner']/h1"));
       String text = GmailText.getText();
       if(text.equals("One account. All of Google."))
       {
       System.out.println("----------Sign out was successful -------");
       }
     else
       {
        System.out.println("----------Sign out wasn't successful ----------");
	}
        }

    catch(Throwable e)
        {
	System.out.println("Sign out link not found: "+e.getMessage());
        }


    // CASE- 2. Both Email and Password Fields are blank.
    try
        {
	WebElement button = driver.findElement(By.id("signIn"));
button.click();			        
WebElement GmailText = driver.findElement(By.xpath("//*[@id=':36']"));
String text = GmailText.getText();
if(text.equals("Primary"))
{
   System.out.println("----------Sucessful Login -------");
}
else
{
	System.out.println("----------Login Failure ----------");
		}
		
}
catch(Throwable e)
{
		System.out.println("Error! Email and Password fields are blank. \n----------------------- ");
System.out.println("Element not found: "+e.getMessage() + "\n-----------------------");
  }


// CASE- 3. Email field is filled and Password field is blank
try
{		
		WebElement email = driver.findElement(By.id("Email"));
email.sendKeys("abcd123@gmail.com");
WebElement button = driver.findElement(By.id("signIn"));
button.click();


WebElement GmailText = driver.findElement(By.xpath("//*[@id=':36']"));
String text = GmailText.getText();
if(text.equals("Primary"))
{
System.out.println("----------Sucessful Login -------\n-----------------------");
}
else
{
System.out.println("----------Login Failure ----------\n-----------------------");
		}
		
 }
catch(Throwable e)
 {
		System.out.println("Error! Password field is blank. \n-----------------------");
System.out.println("Element not found: "+e.getMessage() + "\n-----------------------");
 }	

driver.findElement(By.id("Email")).clear();			// Clearing the Email field


// CASE- 4. Email field is blank and Password field is filled

try
{		
		WebElement password = driver.findElement(By.id("Passwd"));
password.sendKeys("ENTER PASSWORD");
WebElement button = driver.findElement(By.id("signIn"));
button.click();


WebElement GmailText = driver.findElement(By.xpath("//*[@id=':36']"));
String text = GmailText.getText();
if(text.equals("Primary"))
{
System.out.println("----------Sucessful Login -------");
}
else
{
System.out.println("----------Login Failure ----------");
		}
			
}
catch(Throwable e)
{
    	System.out.println("Error! Email field is blank. \n-----------------------");
System.out.println("Element not found: "+e.getMessage() + "\n-----------------------");
 }
  
driver.findElement(By.id("Passwd")).clear();			// Clearing the Password field


//CASE- 5. Email and Password are entered wrong 	

try
{
		 WebElement email = driver.findElement(By.id("Email"));
 email.sendKeys("ENTER INCORRECT MAIL ID");
 WebElement password = driver.findElement(By.id("Passwd"));
 password.sendKeys("ENTER INCORRECT PASSWORD");
 WebElement button = driver.findElement(By.id("signIn"));
 button.click();
 
 WebElement GmailText = driver.findElement(By.xpath("//*[@id=':36']"));
 String text = GmailText.getText();
 if(text.equals("Primary"))
 {
 System.out.println("----------Sucessful Login -------");
 }
 else
 {
 System.out.println("----------Login Failure ----------");
		 }
		 
  }
catch(Throwable e)
{
	
	  System.out.println("Error! Incorrect Email and Password. \n-----------------------");		  
  System.out.println("Element not found: "+e.getMessage() + "\n-----------------------");
}
 
driver.findElement(By.id("Email")).clear();			// Clearing the Email field
driver.findElement(By.id("Passwd")).clear();			// Clearing the Password field
		
	
 // CASE- 6. Email is wrong and Password is correct 	
 try 
 {
	 
		WebElement email = driver.findElement(By.id("Email"));
email.sendKeys("ENTER INCORRECT EMAIL ID");
WebElement password = driver.findElement(By.id("Passwd"));
password.sendKeys("ENTER CORRECT PASSWORD");
WebElement button = driver.findElement(By.id("signIn"));
button.click();
WebElement Inbox = driver.findElement(By.xpath("//*[@id=':53']/div/div[1]/span/a"));
if(Inbox != null) 
{
System.out.println("Sucessful Login \n -----------------");
} 
else 
{
System.out.println("Login Failure");
		}
  } 
 catch(Throwable e) 
 {
	  
	  System.out.println("Error! Incorrect Email. \n-----------------------");
  System.out.println("Element not found: "+e.getMessage() + "\n-----------------------");
  }
 
  driver.findElement(By.id("Email")).clear();			// Clearing the Email field
  driver.findElement(By.id("Passwd")).clear();			// Clearing the Password field
  
  
//CASE- 7. Email is correct and Password is wrong 	
 try
 {
		 WebElement email = driver.findElement(By.id("Email"));
 email.sendKeys("ENTER CORRECT EMAIL ID");
 WebElement password = driver.findElement(By.id("Passwd"));
 password.sendKeys("ENTER INCORRECT PASSWORD");
 WebElement button = driver.findElement(By.id("signIn"));
	 button.click();
	 
 
	 WebElement GmailText = driver.findElement(By.xpath("//*[@id=':36']"));
 String text = GmailText.getText();
 if(text.equals("Primary"))
 {
 System.out.println("----------Sucessful Login -------");
 } 
 else
 {
 System.out.println("----------Login Failure ----------");
			}
  }
 catch(Throwable e)
 {
	   System.out.println("Error! Incorrect Password. \n-----------------------");			  
   System.out.println("Element not found: "+e.getMessage() + "\n-----------------------");
  }

  driver.findElement(By.id("Email")).clear();			// Clearing the Email field
  driver.findElement(By.id("Passwd")).clear();			// Clearing the Password field

//closing current driver window	
		driver.close();
		
	}

}

In the console bar, the output will be seen like this-

2

 

Hope this helps beginners.

Thanks for reading.

How to select Radio Buttons, Drop downs using Selenium webdriver

In this post,I will be going to discuss about selecting Radio Buttons and Drop downs using Selenium webdriver.

Drop downs are selected in many ways. Here I will be discussing how an element from drop down is getting selected using SELECT TAG. The select Tag, you can find in the HTML. There are ‘selectByVisibleText’ , ‘selectByIndex’ and ‘selectByValue’ methods.

Lets take an example of Yahoo registration page.

  1. Login in to yahoo site ( ” https://in.yahoo.com “)
  2. By using mouse hover action in Sign-in field, click on sign up.
    More details in mouse hover action you can find on https://siprabugtracker.wordpress.com/2014/11/25/mouse-hover-action-using-selenium-webdriver/
  3. From the Date field, select a date (6th) from the Drop Down.
  4. From the Month field, select a Month (January) from the Drop Down.
  5. From the Year field, select a year (2013) from the Drop Down.
  6. From the Gender section, click on the female radio button.
  7.  Don’t close the browser as you will see the output as 6 January 2013, Female.
package package1;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;

public class Yahoo_registration {

	public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
// Initialize WebDriver
WebDriver driver = new FirefoxDriver();

// Maximize Window
  driver.manage().window().maximize();
  
// Wait For Page To Load
 driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

 //Navigate to Yahoo webstites
 driver.get("https://in.yahoo.com/?p=us");

// Mouse Over On " Sign-In button  " 
 
 Actions a1 = new Actions(driver);
 a1.moveToElement(driver.findElement(By.xpath("//em[@title='Sign In']"))).build().perform();
 Thread.sleep(3000L);
 System.out.println("clicked on the Sig-in button");
 
// Wait For Page To Load
 driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
 
 //Click on the Sign Up Button
 driver.findElement(By.xpath("//span[@class='y-hdr-ln sign-up-btn']/a")).click();
 System.out.println("clicked on the Sig-Up button");
   
     
// so if a web drop down is getting developed using SELECT TAG in html the following code is implemented 
// -----------
// Select Date 
Select date =new Select(driver.findElement(By.id("day")));
 	
// Select date ["2"]  by Index  
// date.selectByIndex(2);
 
 
// Select date ["6"]  by Value        
date.selectByValue("6");	
driver.findElement(By.id("day")).getText();

 System.out.println("Date = 6th");
   
// Select MONTH 
 Select month =new Select(driver.findElement(By.id("month")));

 // Select month ["MAY"]  by Index  
 month.selectByIndex(5);
 
 // Select month ["OCTOBER"]  by Value        
 month.selectByValue("10");
   
 // Select month ["January"]  by Visible Text	     
 month.selectByVisibleText("January");
     
 System.out.println("month = January");
     
 // --------------
     
// Select Year

Select year =new Select(driver.findElement(By.id("year")));
    
// Select year ["2012"]  by Index
  
year.selectByIndex(3);
System.out.println("Year = 2013");
 

// -------------
// Select Gender
 driver.findElement(By.xpath("//*[@id='gender-wrapper']/fieldset/div/label[2]")).click();

 
 System.out.println("Gender = Female");
   
 System.out.println("The Output of the Gender(Female) Is Enabled : " + driver.findElement(By.xpath("//*[@id='gender-wrapper']/fieldset/div/label[2]")).isEnabled());
 System.out.println("The Output of the Gender Is Displayed : " + driver.findElement(By.xpath("//*[@id='gender-wrapper']/fieldset/div/label[2]")).isDisplayed());
     
}
	    

}


Hope this helps the beginners.

Thanks for reading.

 

Locating Elements on a web page

In my previous article I have written about Browsers Commands.

In a webpage there are different Web Elements present like Buttons, Inputs boxes, Links, Drop-down lists, Check-boxes, Radio buttons, Plain texts and other items.To interact with the above elements we need to locate them first. Selenium provides number of Locators to locate the elements.

The different types of locator are-

  • Locating By Id
  • Locating By Name
  • Locating By Class Name
  • Locating by Tag Name
  • Locating Hyperlinks by LinkText
  • Locating By Xpath
  • Locating By CSS

Locating elements on a webpage can be done using the findElement and findElements method.

findElement() –

  • This method will find the first element within the current page using the given “locating mechanism”.
  • It returns a single WebElement.
  • If “findElement” will not find any element within the page then it will throw NoSuchElementException.
  • Syntax – WebElement findElement(By. “ANY LOCATOR”);

findElements() method –

  • This method is use to find multiple element on webpage.
  • It returns a list of WebElements.
  • If no element is not found, it will return empty List of WebElement and no exception will be thrown.
  • Syntax – java.util.List<WebElement> findElements(By. “ANY LOCATOR”);

Now we have to install 2 plugins[Firebug, Firepath] so as to integrate it with Firefox as it will help us to inspect the element and to generate Xpath.

  • First Add Firebug to the Firefox. Click this link to Add.
  • After integrating the FireBug with Firefox add FirePath from this Link.

Now Open the Firebug by Pressing F12 on your keyboard. Then click on the inspect Element icon in the Firebug. It will show the html view of that particular element. See below for the image.

1

Now Lets discuss the Syntax for each Locator.

  • Locating Element By.Id()-

By.Id  – This helps to find the element using the Id.

Syntax-

driver.findElement(By.id(“id of the element”));

  • Locating Element By.Name() –

By.Name – This helps to locate the element by the value of the “name” attribute.

Syntax-

driver.findElement(By.name(“name of the element”));

  • Locating Element By.tagName() –

By.tagName – This helps to locate the web element based on the HTML tag.

Syntax-

driver.findElement(By.tagName(“tagname”));

  • Locating Element By.linkText() –

By.linkText – This helps to locate the element by text displayed on link.

Syntax-

 driver.findElement(By.linkText(“link text”));

  • Locating ElementBy.partiallinkText: It is same as Link text. Only difference is here it helps to locate the  link element which is having partial matching text.

Syntax-

driver.findElement(By.partiallinkText(“partial text”));

  • By.ClassName :- This helps to locate the web element based on the“class” attribute.

Syntax-

driver.findElement(By.className(“Name of the class”));

  • By.xpath:- This helps to locate elements via xpath.

Syntax-

driver.findElement(By.xpath(“xpath of the element”));

  • By.cssSelector:- This helps to locate element using the CSSSelector.

Syntax-

driver.findElement(By.cssSelector(“selector”));

So, in this post we discussed about the different ways of Locating Elements on a web page. Hope this article will help you 🙂

Selenium WebDriver Browser Commands

Introduction

In this part of my article, we are going to discuss about various browser commands that we would be using in our day to day life in testing. Opening and closing a browser is the very first thing in Selenium, a tester would like to do. The commands refers what Selenium has to do. Justlike a master commands a slave in early days!! sorry even today. OK!! Lets not get social now.
So here we discuss regarding the commands we give to the Selenium in order to perform some specific task.

Below are different basic commands, which we will encounter while witting the scripts.

Get Commands

Get commands are used to collect various information about the page that we deal with Here are some important “get” commands you must be familiar with.

  1. Get Command – ” get() “

get() command is used to open a new browser window and it will find/fetch the page that you have given.

2. Get Title Command- ” getTitle() “

getTitle() is used to get the title of the current page.

3. Get Current URL Command- ” getCurrentUrl() “

This command is used to get the current URL of the browser.

4. Get Page Source Command – ” getPageSource() “

This command is used to get the source code of the page.

5. Get Text – ” getText() “

This command is used to fetch the text of the element.

NAVIGATE COMMANDS

1. Navigate To Command– ” navigate().to() “

This command is like Get() command.

It open  a new browser window and it will find/fetch the page that you have given.

2. Navigate Refresh Command– ” navigate().refresh()

This command is used to refresh the current page.

3. Navigate to back page– ” navigate().back()

This command is used to go back by one page on the browser’s history.

4. Navigate to froward page– ” navigate().forward()

Takes you forward by one page on the browser’s history.

5. Refresh page – ” navigate().refresh()

It refreshes the current page.

OTHER USEFUL COMMANDS
1. SwitchTo command – ” driver.switchTo().window(“windowName”) ”

This command is used to switch from one window to another.

2. Switching  from one iframe to another – ” driver.switchTo().frame(“frameName”) ”

This command is used to switch from a one iframe to another iframe.

3. Handling Alerts – ” driver.switchTo().alert() ”

This command is used to handle alerts.

4. Close Command – ” close()

This command close the current window of the browser.

5. Quit Command – ” quit()

This command is use to quit the browser and all the opened windows in the browser.

These are the basic commands that are needed for witting simple script.

Now by using these commands I will automate a browser by writing scripts so that we can have a clear idea, of how to use these commands.

Test scenario –

  • Open a Firefox Browser.
  • Put a Implicit wait.
  • Navigate to the URL.
  • Maximize the window.
  • Store the Title Name.
  • Print the Title Name.
  • Store Title Length.
  • Print Title Length.
  • Store the URL Name.
  • Print the URL Name.
  • Store URL Length.
  • Print URL Length.
  • Print the name of Tab which is going to be clicked suppose [NEWS TAB].
  • Click on NEWS Tab.
  • Store the Text of an element of the new opened tab.
  • Print the Text Name of an element of the new opened tab.
  • Now Navigate to the previous page.
  • Print the Title of the previous page.
  • Now Navigate to the next page.
  • Print the Text of the next page.
  • Refresh the current page.
  • Store the Page Source in String variable.
  • Print the Page Source Name.
  • Store Page Source Length in Integer Variable.
  • Print Page Source Length.
  • Close the browser or page currently which is opened.

The Code/Snippet goes as below:-

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Commands {

public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();

// Wait For Page To Load
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

// Go to URL
driver.get("http://www.bbc.com/");

// Storing Title name in String variable so that we can get the title name
String btitle = driver.getTitle();

// Printing the Title name in 2 ways
// 1st way
System.out.println(btitle);
// 2nd way
System.out.println("Title is : " + btitle);

// Storing Title length in Int variable because we are dealing with Integers that's why int is used.
int bTitleLength = driver.getTitle().length();

// Printing Title l0ength
System.out.println("Length of the Title is : " + bTitleLength);
// Storing URL in String variable
String b1 = driver.getCurrentUrl();

// Printing URL on Console Window

System.out.println("URL is : " + b1);

// Storing URL length
int b2 = driver.getCurrentUrl().length();

// Printing URL length on console Window

System.out.println("URL length is : " + b2);

// COMMAND FOR NAVIGATION THROUGH PAGES.

//Open the NEWS Page.
String b3 = driver.findElement(By.xpath("//*[@id='blq-nav-news']/a")).getText();

// Print the Tab name which is being clicked.
System.out.println("Name of the Tab which is being clicked is : " + b3);

// Click on the Tab
driver.findElement(By.xpath("//*[@id='blq-nav-news']/a")).click();

//Get the text where Xpath is pointing.
String b4 = driver.findElement(By.xpath("//*[@id='header']")).getText();

// Print the text of the current page
System.out.println("Text of current page is : " + b4);

//Navigate to previous Page.

driver.navigate().back();
Thread.sleep(1000);
String b5 = driver.getTitle();

// Print the text of the previous page
System.out.println("Text of the previous page is : " + b5);

//Navigate to Next page.
driver.navigate().forward();
Thread.sleep(1000);
// Print the text of the NEXT page
String b6 = driver.getTitle();
System.out.println("Text of the NEXT page is : " + b6);
// COMMAND FOR REFRESHING THE CURRENT PAGE

// driver.get(driver.getCurrentUrl());
driver.navigate().refresh();

// PAGE SOURCE COMMAND
// Storing Page Source in String variable.
String b7 = driver.getPageSource();
Thread.sleep(1000);

// Printing the Page Source
System.out.println("Page source : " + b7);

// Storing Page Source length in Int variable
int b8 = driver.getPageSource().length();

// Printing the Page Source length
System.out.println("Length of the page source is : " + b8);

//close the browser or page currently which is having the focus.
driver.close();

//Close all the windows.
//driver.quit();
}
}

SwitchTo command
Switching  from one iframe to another
Handling Alerts
The above three Useful commands are not covered in this part of the Article, I will be penning these details in my upcoming article.
Hope this helps anyway to beginners in testing.
Thanks.
🙂

A small Tip for – How to take Screen Shot using Selenium WebDriver?

In the previous blog we had discussed in short , ” How to automate a browser !! “. As a beginner like me,  you will be very keen to take screen shot of a particular page.

Here is a simple script for taking screen shot of any URL. I have taken “http://www.flipkart.com/&#8221; as mu URL.

package login;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Screen_shot {

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub

// Initialize WebDriver
WebDriver driver = new FirefoxDriver();
// Wait For Page To Load

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
// Go to URL
driver.get("http://www.flipkart.com/");
// Maximize Window
driver.manage().window().maximize();
// Take ScreenShot
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("D:\\selenium\\screenshot1.png"), true);
// Close Driver
driver.quit();
}
}

Below are few points with images.

  • 13456
  • For the above image you have to Import this package only [  ‘FileUtlis’ (org.apache.commons.io) ]
  • After completion of the script, the PNG file will be stored in your given location. I have given [ “D:\\selenium\\screenshot1.png” ]. Here is the screen shot below.

File has been saved in the format i.e png as mentioned in the script.

  • File has been saved in the format i.e “png” as mentioned in the script. We can save the image in different file type like PNG, JPEG, GIF, BMP.

Hope this helps Beginners like me… 🙂