Frames.html

10:04 PM 0 Comments

<!DOCTYPE html>
<html>

<frameset cols="25%,*,25%">
  <frame src="frame_a.html" name="frame_a">
  <frame src="frame_b.html" name="frame_b">
  <frame src="frame_c.html" name="frame_c">
</frameset>

</html>

0 comments:

frame_a.html

10:04 PM 0 Comments

<html>
<head>
 <style>
  #mycolor1 {color: blue;}    
  .mycolor2 {color: blue;}
  .textbox{background-color:yellow}
 </style>
 <div  style="background-color:yellow;text-align:center"><h2>Frame 1 </h2></div>
</head>

<body bgcolor="blue">
       <center><input type="text" value="Iam in Frame1" id="Frame1txt" /></center>
   
</body>
</html>

0 comments:

frame_c.html

10:04 PM 0 Comments

<html>
<head>
 <style>
  #mycolor1 {color: blue;}    
  .mycolor2 {color: blue;}
  .textbox{background-color:yellow}
 </style>
 <div  style="background-color:red;text-align:center"><h2>Frame 3 </h2></div>
</head>

<body bgcolor="purple">
  <center><input type="text" value="Iam in Frame3" id="Frame3txt" /></center> 
</body>
</html>

0 comments:

Working with frames,frameSet,iframes in Selenium WebDriver using CoreJava(TargetLocator)

9:49 PM 0 Comments







Handling Frames using TargetLocator(switchTo())!!!
Generally when ever we open the page we don't find the frames for every application. Ex: Facebook.com doesn't have frames. If we want to confirm whether frames are implemented for the web application we can follow 
steps mentioned below:
1. Open Firefox
2. Enter the Url http://www.facebook.com
3. Click on Firebug plugin.
4. Navigate to Firepath plugin.
5. Check the screenshot as mentioned below. Based on this we can decide whether the frames are implemented for this application.







Also, if we want to perform any action say enter the text in the textbox available in the Frame. we have to use following methods:
driver.switchTo().frame(int index)- index starts from zero.
or
driver.switchTo().frame(String framename)
Download the html source code from these links:
1. Frames.html
 https://tobeanexpert.blogspot.com/b/post-preview?token=w7uC8EwBAAA.5IP50O0wZ0fsnoaOe5jiLQ.lYohA8_aM5FeDVfOJAyW_A&postId=629786504598294227&type=POST
2. frame_a.html 
https://tobeanexpert.blogspot.com/b/post-preview?token=DHWE8EwBAAA.5IP50O0wZ0fsnoaOe5jiLQ.OU_N6UQ4tzlB7XypI_Se_A&postId=1277459784965833367&type=POST
3. frame_b.html 
https://tobeanexpert.blogspot.com/b/post-preview?token=cluH8EwBAAA.5IP50O0wZ0fsnoaOe5jiLQ.1JCsNYQVBnWsiXWYmOcl1Q&postId=3121611285388662540&type=POST
4. frame_c.html 
https://tobeanexpert.blogspot.com/b/post-preview?token=vo6H8EwBAAA.5IP50O0wZ0fsnoaOe5jiLQ.DjH_UeWElg9eQ_06IQETBw&postId=7113507276382232086&type=POST
After downloading the html examples from the (1-4) links opening the Frames.html it looks like web-application the finally as below






Program: HandlingFrames.java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class HandlingFrames {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("file:///D:/Selenium/HTML/Frames.html");
//switch to a particular frame from the topwindow using index
driver.switchTo().frame(2);
driver.findElement(By.id("Frame3txt")).clear();
driver.findElement(By.id("Frame3txt")).sendKeys("in frame3");
//Switches the frame to a top window
driver.switchTo().defaultContent();
driver.switchTo().frame("frame_a");
//driver.switchTo().frame(driver.findElement(By.id("Frame1txt")));
driver.findElement(By.id("Frame1txt")).clear();
driver.findElement(By.id("Frame1txt")).sendKeys("in frame1");
//Switches the frame to a top window
driver.switchTo().defaultContent();
driver.switchTo().frame("frame_b");
driver.findElement(By.id("Frame2txt")).clear();
driver.findElement(By.id("Frame2txt")).sendKeys("in frame2");
}
}
Handling iFrames using TargetLocator(switchTo())!!!
Usually idenfitying Frames is easy becoz when defining the frames the developer provides the properties of the frame say name and id.
In the below examples the frame name is provided which is easy we can switch using driver.switchTo().frame("frame_a");
<!DOCTYPE html>
<html>

<frameset cols="25%,*,25%">
  <frame src="frame_a.html" name="frame_a">
  <frame src="frame_b.html" name="frame_b">
  <frame src="frame_c.html" name="frame_c">
</frameset>

</html>
But in the case of iframe its totally different. No properties defined for iframe then how do we switch??? 
<!DOCTYPE html>
<html>
<body>
<iframe width="100%" height="300px" src="iframedemo.htm">
</iframe>
</body>
</html>
To understand this better check the page source of the html file "iframedemo.htm". It contains one textbox box named "frame1txt".
Now we can switch to this iframe using the following method:
driver.switchTo().frame(driver.findElement(By.name("frame1txt")));
<html>
<body style="background-color:#F5DEB3">
<h1>This page is displayed in an iframe</h1>
Username:<input type="text" name="frame1txt" id="frame1txt">
</body>
</html>
Download the html source code from these links:
1. Handlingiframes.html
2. iframedemo.htm








Program: HandlingIFrames.java
public class HandlingIFrames {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("file:///D:/Selenium/HTML/Frames.html");
//switch to a particular iframe using the webElement
driver.switchTo().frame(driver.findElement(By.name("frame1txt")));
   driver.findElement(By.name("frame1txt")).sendKeys("selenium");
 }
}

References:http://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebDriver.TargetLocator.html

0 comments:

Selenium WebDriver- Debugging Code (Breakpoints) - Java Debugging with Eclipse

12:55 AM 28 Comments









Most of us interested to know, how the code is getting executed. Some times, even if we write the code with out having any syntax errors also during execution we face issues which requires debugging of the code.
As Web-driver script executes fast, if we want to execute the Web-driver  code line-by-line and verify the Output can be achieved using the Debug Mode in Eclipse.
Lets start. I have written a very simple example in Selenium Webdriver to retrieve the text in Facebook as highlighted in the below image.









Facebook.java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Facebook {

public static void main(String[] args) {

WebDriver driver = new FirefoxDriver();
driver.get("https://www.Facebook.com");
String actual = driver.findElement(By.xpath("//span[text()=' See photos and updates ']")).getText();
System.out.println(actual);
String expected = " See photos and updates";

if(actual.equals(expected))
{
System.out.println("Actual is equal to Expected TC - Pass");

}
else
System.out.println("Actual is not equal to Expected TC - Fail");
}

}
There are no syntax errors in the code. Please try to execute the code as shown below:








Output:
Actual is not equal to Expected TC - Fail
In the above scenario the TC should pass. But we are getting response as TC-Fail.
So, how do we identify the issue. What is the reason for failure.
We have to use Debug mode to identify the root-cause for this issue.
Debug - Step1- Insert BreakPoint
Right-click at the line number 10 and select the first option - 'Toggle Breakpoint'. It means we are inserting the Breakpoint, so we can verify the values in the variable at run time.
In our case we can verify the value stored in the 'actual'.










Step2-Run Facebook.java in Debug mode










Step3- Debug Perspective opens as shown below
Select the checkbox-'Remember by decision' and click on 'Yes' button.









The Debug perspective opens, it has three tabs Variables,Breakpoints,Expressions.








Out of three tabs- Expressions tab is required to view the values at run-time.In Debug perspective if you are unable to identify this tab. You to follow the steps as show below:






Navigate to Expression tab and click on 'Add new expression' enter 'actual' as shown below:









Click on Step-Over to move to next step. Verify the 'actual' value in the Expression tab.Also add few more expressions as shown below:
Actual String length-> actual.length()
Expected String length()->expected.length()








Click on Step-Over to move to next step. Verify all the values as shown below:







Conclusion
The length of expected String is 23.
The length of actual String is 22. 
So there is an issue in expected string. In the program we provided the String expected =" See photos and updates";
There is an unnecessary space added in the string. It should be changed to String expected ="See photos and updates";
by removing the unwanted spaces.
Once identify the issue click on terminate button as shown below.







Change the Perspective from Debug Mode to Java Mode.







Remove all the breakpoints.

28 comments:

Selenium Automation Resume - Highlights Roles & Responsibilities

11:46 PM 1 Comments

Resume Highlights:
--------------------------
Having 7+ years of experience in Manual and Automation Testing.
Experience in Selenium WebDriver using Core Java.
Experience in designing the Java Frameworks like Testng.
Experience in designing the automation frameworks like Data-driven and Modular
Driven using Page Object Model.
Hands-on-Experience in performing cross browser testing using Testng and Grid.
Good Knowledge in HTML and XML.
Experience in understanding and writing testcases.

Responsbilities:
------------------
Performed regression and sanity testing for the project.
Raised the bugs in Bugzilla/Jira.
Provide the logs and screenshots while raising the bugs which gives
more information to developer to fix the defect on-time.
Design the Framework using ...
Automate the testcases using Selenium Webdriver with Java Framework Testng.
Report the results to the stake holders.
Invovled in the module of the project.
Worked effeciently to make sure the project is released on time with high quality.

1 comments:

Selenium-CoreJava Interfaces in JAVA!!!!

1:12 AM 0 Comments












Objective: Find out the reusable methods and create a super class for all the browsers like IE,FF,CH.

public abstract class WebDriver
{

public abstract void openBrowser(String url);

public abstract void closeBrowser();

}

Interface Definition:
-----------------------------

If the class contains 100% abstract methods then the class is defined as interface.
public interface WebDriver
{

public void open(String url);

public void close();

}
1. An interface contains 100% abstract methods.
2. In interface methods are by default public and abstract.

public interface WebDriver
{

void open(String url);

public abstract void close();

}
3. In interface, variables are 'public static final' by default.

public ->Accessible everywhere
static->Classname.variable
final->Constant. Once intialized we cannot re-assign the new value;

4. The final variables in interface are intialized at the time of declaration.
int i;//declaration
i=10;//intialization or Assignment

int i =10;//Declaration and intialization.

5.A class uses an interface should use an keyword called 'implements'.


IE,FF,CH

public class IEDriver implements WebDriver
{
void open(String url){}
public void close(){}
}

public class FFDriver implements WebDriver
{
void open(String url){}
public void close(){}
}

public class CHDriver implements WebDriver
{
void open(String url){}
public void close(){}
}

6. A class can implement multiple interfaces, but extends only one class at a time.

   A interface extends an another interfaces

7. A class together can use implements and extends keywords together.

public class ThreadEx extends ClassB implements Runnable,InterfaceA
{

}

If a class is implementing an interfaces then we can write as follows:

InterfaceName refV = new ClassName();

WebDriver      driver = new FFDriver();

driver.open("http://www.google.com");
driver.close();


final variables are constants
--------------------------------------
public final int i =20;
i=10;// not possible i is final

final classes cannot be extended
----------------------------------------
public final class String
{
}
public class A extends String// cannot extend an final class
{

}
final methods cannot be overriden
--------------------------------------------
public final void equals()
{


}
@Override:
-------------------
Whenever the same method name with same parameters available in the super class and 
subclass or interface and subclasses.. those methods are overriden methhods.
@Override is an annotation which is an special instruction to the compiler.

0 comments:

Selenium - Core Java OOPs Concept - Inheritance (Reusability)

2:09 AM 1 Comments

Advantages of re-usability:

1. Save time and effort
2. Maintenance of code is easy means if you want to modify the code. We will change the code in one place.









OOPs Concept Inheritance: 

1. The objective of inheritance is re-usability.

2. The process of acquiring the methods and variables from Super-class to Sub-Class is called Inheritance.

Class members are methods and variables.

Two types of class members -> static and nonstatic

Static Members are accessed using Class Name:
public static void display()
{

}

Non-Static Members are accessed using Object:
public void display()
{

}

Only object level class members are inherited to subclass.


3. Inheritance is achieved between two classes using the keyword called 'extends'. From now on-wards 'extends' means inheritance.

4. Single Inheritance is between two classes is achieved using the extends keyword

Class A
{
public int i=20;

public void display()
{
}

}

Class B extends ClassA
{

}



5. Multilevel Inheritance : mean the subclass(child) can access superclass(Father) and Superclass SuperClass (GrandFather) also.

  Class A   
  {


 }


 Class B extends Class A
 {


 }



 Class C extends Class B
 {


}

6. Multiple Inheritance:

   In java we cannot extend more than one class at a time.
   Multiple classes cannot be inherited at the same time.
   So, multiple inheritance is not supported in java.


   Class C extends Class B,Class A  //Not Valid in java

   Diamond Problem in java.


7. By Default a Class extends Object Class. So we can access the object class Members. Object is a class available in the package java.lang.

8. Only non-static variables and methods are inherited to the subclass.  Static variables and Methods are at the class level not at the object  level. So cannot be inherited to the subclass.

9. Global and Local Variables

public class Variables {


int a = 20; // Global variable

public static void main(String[] args) {

int a =10;
System.out.println(a); // local variable

Variables v = new Variables();
System.out.println(v.a);


}


}

1 comments:

Cross Browser Testing on Selenium (IE,FF,Chrome) - InternetExplorerDriver,ChromeDriver,FirefoxDriver

12:12 AM 1 Comments

Compatibility Table for Selenium Jar Versions 2.44.0 & 2.45.0 and Browser Versions!!!






We have to set the System properties to execute the Selenium Web-Driver Script on Internet Browser (IE)


Pre-requisite for IE Browser->
1.  Download the zip file as mentioned in the above table.
Example: 
Suppose if am using selenium-java.2.45.0.zip in your project. Please  download the IE Driver from the link as http://selenium-release.storage.googleapis.com/2.45/IEDriverServer_x64_2.45.0.zip
2. Unzip the file. It contains the following files.









3. Right click on the IEDriverServer.exe file and  get the path of the IEDriverServer.exe. Make a note of it and update the location in the below program.




























Path to the File  IEDriverServer.exe -> 
D:\\Selenium\\Selenium Jars\\IEDriverServer_x64_2.45.0\\IEDriverServer.exe

System.setProperty("webdriver.ie.driver","D:\\Selenium\\Selenium Jars\\IEDriverServer_x64_2.45.0\\IEDriverServer.exe");

Program -> IEDriver.java
package Browsers;

import java.io.File;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;


public class IEDriver {


public static void main(String args[]) 
{
 //Setting the System Property
System.setProperty("webdriver.ie.driver","Path to the File  IEDriverServer.exe");  
WebDriver driver = new InternetExplorerDriver();
driver.get("http://dl.dropbox.com/u/55228056/bmicalculator.html");//Invocation
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(1,TimeUnit.MINUTES);
WebElement height = driver.findElement(By.id("heightCMS"));
height.sendKeys("181");
}

}

Issues faced during the execution of Selenium WebDriver Script against the Internet Explorer Driver:
Issue 1: Zoom should be set to 100%
Exception:
Started InternetExplorerDriver server (64-bit)
2.25.2.0
Listening on port 14060
Exception in thread "main" org.openqa.selenium.WebDriverException: Unexpected error launching Internet Explorer. Browser zoom level was set to 0%. It should be set to 100% (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.70 seconds
Solution:
zoom percentage for IE should be set to 100%.  To verify Goto ->View->Zoom (100%)
Issue 2: protected-mode should be set to same level for all the zones.
Exception:
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)

Command duration or timeout: 1.39 seconds
Build info: version: '2.34.0', revision: '11cd0ef', time: '2013-08-06 17:11:28'
System info: os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_09'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver

Solution:
This error is because of the security settings in IE.
>> Open IE , then go to Tools>>Security tab .
>>Now either check or uncheck the "Enable Protected Mode" checkbox for all zones i.e Internet , Local internet, Trusted Sites, Restricted Sites.

Executing the Selenium Web-Driver Script on Chrome Browser:
Pre-requisite for Chrome Browser->
1.  Download the zip file as mentioned in the above table.
Example: 
Suppose if am using selenium-java.2.45.0.zip in your project. Please download the Chrome Driver from the link as http://chromedriver.storage.googleapis.com/index.html?path=2.14/
2. Unzip the file. It contains the following files.












3. Get the path of the ChromeDriver.exe. Make a note of it and update the location in the below program.






























Path to the File  IEDriverServer.exe -> 
D:\Selenium\Selenium Jars\chromedriver_win32\\chromedriver.exe

System.setProperty("webdriver.ie.driver","D:\\Selenium\\Selenium Jars\\chromedriver_win32\\chromedriver.exe");

Program->ChromeDriverEx .java
package Browsers;

import java.io.File;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

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

public class ChromeDriverEx {


public static void main(String args[])
{
     //Setting the System Property
    System.setProperty("webdriver.chrome.driver","Path to the File  ChromeDriverServer.exe");  
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://dl.dropbox.com/u/55228056/bmicalculator.html");
driver.manage().timeouts().implicitlyWait(1,TimeUnit.MINUTES);
WebElement height = driver.findElement(By.id("heightCMS"));
height.sendKeys("181");
}


}



1 comments: