Tools required by a Quality Analyst/Tester while testing.

Every Tester should use the below tool while doing testing.

1. Web Developer Tool Bar

It is tool bar which is has a number of menu options for inspecting and debugging web pages.It also includes web services like W3C’S CSS Validator and also check for responsiveness.

2. Firebug – It is an extension of Firefox browser. It allows to inspect, debug the html, dom, css properties and java script. It has different tab in it. One of the tab is Network tab, here we can see the Http request that happens when the page get loads. The status code and the response time is also seen.

3. Xenu – It is a desktop application for Windows that outputs all your site links, whether they’re valid or invalid links and groups them into a very readable fashion.Xenu’s link Sleuth checks Websites for broken links.

These broken links need to be avoided as they have many drawbacks that may lead to huge losses to the website also as they would loose many customers.

4. Yslow– It is an extension of Firebox browser and it is integrated with the Firebug. It measures the page performance and gives suggestion for improvement of the page. It has 34 rules set, from it 23 are testable. We can create our own rule-set to test the application. The page performance is displayed in Grades [ A – F]

5. W3C Validator – It checks the validity of the web document.

6. Spell Checker – It is an extension of the firefox which checks the spelling mistakes and highlights the errors.

7. Fire Shot – It is helpful to take screen shots of entire page/ visible area and save it in pdf or image format. Edit feature is also present.

 

Hope this helps Beginners 🙂

How to Handle Alert Pop up in Selenium Webdriver

Here we will see how alert pop up are handled in webdriver.

package beginner_level;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.Alert;

public class CodeForAlert {

public static void main(String[] args) throws InterruptedException {
// Open in chrome  browser
System.setProperty(“webdriver.chrome.driver”,”D:\\selenium workspace\\chrome\\new chrome 2\\chromedriver_win32(1)\\chromedriver.exe”);

WebDriver driver = new ChromeDriver();

//Open the railway site – [ http://www.indianrail.gov.in/seat_Avail.html ]
driver.get(“http://www.indianrail.gov.in/seat_Avail.html”);
// Click on the “Get Availability” icon
driver.findElement(By.xpath(“//input[contains(@value,’Get Availability’)]”)).click();
// Check the alert box
Alert a1= driver.switchTo().alert();
// Get the text from alert box
String s = a1.getText();
Thread.sleep(3000);
// Print the text
System.out.println(“Text present in alert box is – ” + a1);
// Click on ok
a1.accept();
// Print the success text after alert is closed
System.out.println(“Alert box is closed now”);

// Close the browser
driver.close();
}

}

How to get the number of count of text boxes present in a page using Selenium WebDriver.

package beginner_level;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class ExtractAllTextBoxes {

public static void main(String[] args) {
System.setProperty(“webdriver.chrome.driver”,”D:\\selenium workspace\\chrome\\new chrome 2\\chromedriver_win32(1)\\chromedriver.exe”);
WebDriver driver = new ChromeDriver();
// Open Google website
driver.get(“https://accounts.google.com/SignUp”);

// In HTML, the  input fields or text boxes are of type- text or password.
java.util.List<WebElement> textfield = driver.findElements(By.xpath(“//input[@type=’text’ or @type=’password’]”));
// Number of text boxes present.
int nsize = textfield.size();
System.out.println(“Number of text boxes are –  ” + nsize);
// Here you can enter the text in the text boxes present in the page and cross check it.
for(int i=0; i< nsize; i++){
textfield.get(i).sendKeys(“Text” + (i+1));
}

}
}

How to set Browser width and height in selenium webdriver.

package beginner_level;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class SetBrowserWidthHeight {

public static void main(String[] args) {

// Open in chrome browser
System.setProperty(“webdriver.chrome.driver”,”D:\\selenium workspace\\chrome\\new chrome 2\\chromedriver_win32(1)\\chromedriver.exe”);

WebDriver driver = new ChromeDriver();

//Open the railway site – [ http://www.indianrail.gov.in/seat_Avail.html ]

driver.get(“http://www.indianrail.gov.in/seat_Avail.html&#8221;);

// Set the browser width=500 and height = 500
Dimension d = new Dimension(500,500);
driver.manage().window().setSize(d);

}

}

Hope this helps Beginners 🙂

How to extract all links of a page using Selenium WebDriver.

package beginner_level;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class ExtractAllinks {

public static void main(String[] args) {
System.setProperty(“webdriver.chrome.driver”,”D:\\selenium workspace\\chrome\\new chrome 2\\chromedriver_win32(1)\\chromedriver.exe”);
WebDriver driver = new ChromeDriver();
// Open Google website
driver.get(“https://www.google.com&#8221;);

// In HTML, the links start with anchor “a” tag. so we can find find the elements starting with “a”.
java.util.List<WebElement> links1 = driver.findElements(By.tagName(“a”));
// Number of links present.
int nsize = links1.size();
System.out.println(“Number of links are –  ” + nsize);

for(int i=0; i< nsize; i++){
String text= links1.get(i).getText();
System.out.println(“Name of the link ” + i + ” – “+ text);
}

}

}

Hope this helps Beginners:)

How to run Webdriver in Chrome Browser.

Here I will describe how the application will run in Google Chrome.

1. Go to this link – https://sites.google.com/a/chromium.org/chromedriver/downloads
2. Check your chrome version [ Customize and control Google Chrome → Help → About Google Chrome] and accordingly choose the Chrome Driver.
3. In my system I have chrome 49.0.2623.112 m , so I am opening the Latest Release: ChromeDriver 2.21
Screen shot attached.

1
4. Now according to your OS, download the zip file.
5.My system is windows, so I am downloading – chromedriver_win32.zip .
Screen shot attached.

2

6. Place the downloaded zip file in a folder, extract the zip file and note the path.
7. The exe file will look like the below image –

3

8. Now create a Project in eclipse and a class – “ Chrome_Browser ” and write the below code.

 

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Chrome_Browser {

public static void main(String[] args) {

System.setProperty(“webdriver.chrome.driver”,”D:\\selenium workspace\\chrome\\new chrome 2\\chromedriver_win32(1)\\chromedriver.exe”);

WebDriver driver = new ChromeDriver();
driver.get(“http://www.google.com/&#8221;);
System.out.println(“successful”);

}

}

Hope this helps Beginners 🙂

 

 

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.

BROKEN LINKS AND HTTP ERROR CODES

Broken Links, as the words explain themselves, refer to the links/URL that are unavailable or under construction. There are many reason why the Users get error pages popped up due to these broken links. 404 Error, 500 internal server error, 403 error, unauthorized user error and many more. These are all because of broken links that are framed when error occur when the user wants to be redirected to a page that doesn’t exist. This concept has many names like Link Rot, Link dead, that is in simple language the target of reference does not exist.

This irritates many developers and on the other hand helps them giving the information where and what went wrong. But its developers who can understand but, what about the end users? They should get a valid information regarding what is wrong! For instance, 404 error, what does a user know about this? They should get valid response as page is not available or be navigated to some other default page.

There are many reasons for which a link breaks.

  • The most common reason is that the page is no more available.
  • Some websites also refresh the contents of their respective pages, this might lead to a break if the old contents are searched for.
  • Another reason is that if the targeted page hosted by the server changes, and relates to a new Domain name, then the browser would return a DNS error, or say content unavailable.
  • Dead links or Broken Links occur if the URLs are not organized & proper routing is not done.

To understand the Error, we need to know the Status codes that represent the type of error or success response. They are stated below:-

  • 100-199 : informational status
  • 200-299 : success status
  • 300-399 : redirection status
  • 400-499 : client errors
  • 500-599 : server errors

There are many ways to combat this, but we use XENU.

Xenu is a standalone desktop application for Windows that outputs all your site links, whether they’re valid or invalid links and groups them into a very readable fashion.Xenu’s link Sleuth checks Websites for broken links. Some of its features are:-

  • Can re-check broken links (useful for temporary network errors)
  • Simple, no-frills user-interface

  • Simple report format, can also be e-mailed
  • Executable file smaller than 1MB
  • Supports SSL websites (“https:// “)
  • Partial testing of ftp, gopher and mail URLs
  • Detects and reports redirected URLs
  • Site Map

These broken links need to be avoided as they have many drawbacks that may lead to huge losses to the website also as they would loose many customers.

Now lets discuss briefly about the various HTTP status codes, that is important during the development, so that the error can be notified and easily rectified. For instance, suppose Http status code 404 is returned, that simply means that the page referred by the user doesn’t exist & suppose the Http status code is 500(internal server error) this clearly states that there is problem in the called method or the service, that can be avoided debugging and getting to the root of the error.

HTTP 200 OK:-

The request for the page is processed successfully and the contents are returned or displayed to the user successfully. The users barely see this code as almost everytime a success page with the contents are displayed. Sometimes due to some internal problems the success code 200 is returned in place of the actual contents. This is the reponse from the server to the browser.

HTTP 404 NOT FOUND:-

This error code is self explanatory. As mentioned above , this suggests that the requested page doesnot exist or is unavailable. The server gives nothing in response, but ensures that the connection between client and server was made successfully. Another reason may be with the URL, so the user should be concious during writing the URL.

HTTP 500 INTERNAL ERROR:-

This error suggests that the web server got the request but was unable to process that request, this might be caused due to the problem on the server side and that should be avoided or referred to the server administrator or the developer to rectify the problem.

HTTP 503 SERVICE UNAVAILABLE:-

The reason for this error is almost same as the 500 internal error as the server receives the request from client but is unable to process the request. This might be due to unexpected failure at the web server administrator, increase in the subsequesnt/concurrent request from users.

HTTP 301 PERMANENTLY MOVED:-

The URL specified by the user might be moved to some other locations or have their domain names changed.Using a method HTTP Redirect, the user get redirected to the changed URL and the contents which the user was looking for.

HTTP 400 BAD REQUEST:-

The URL specified by the user must not be present or in developer’s language must not have been implemented, for which the request to the server here returns nothing i.e. Nothing was found as such. Thus, that is mentioned as a bad request, which is coded “404”.

 

Conclusion:-

Thus, here we discussed about the broken links and their causes and how a developer can avoid them from being shown or obstructing the users. This is also very much required for the testers to be aware of about this so that they can test and look for the broken links if any present.Broken Links being irritating for the users should always be avoided to ensure their retention. We also discussed about the different types of Http Error codes that are a part of every website.

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.