Tuesday, February 19, 2013

Search and Delete file from directory whose name in Regular Expression pattern

Search and Delete file from directory whose name in Regular Expression pattern

The below code deletes file whose name has "output" and ends with ".xls" from any directory.
Eg : output.xls
 123output123.xls
acvoutput.xls        etc.,





import
java.io.File;
import
java.io.IOException;
//import java.util.Locale;
import
javax.swing.JOptionPane;
import
jxl.*;
import
jxl.write.*;
import
jxl.write.Number;
import
jxl.write.biff.RowsExceededException;
import
jxl.read.biff.BiffException;
//import jxl.write.WritableSheet;
//import jxl.write.WritableWorkbook;
//import jxl.write.*;
import
java.util.regex.Matcher;
import
java.util.regex.Pattern;
 
 
public
class Framework
{
public static void main(String[] args) throws BiffException, IOException, RowsExceededException, WriteException
{
String sDir = JOptionPane.showInputDialog(
"Enter any Directory");
String sTemp;
String pattern =
"(.*)(output)(.*)(xls)";
int i;
//int iSize=Integer.parseInt(JOptionPane.showInputDialog("Enter array size"));
File oDir =
new File(sDir);
String[] aFiles = oDir.list();
for (i=0 ; i <= aFiles.length-1 ; i++ )
{
//sTemp=aFiles[i];
File oF=
new File(sDir+"\\"+(aFiles[i]));
if (cString_match(oF.getName(),pattern) == true ) //aArr[i]=JOptionPane.showInputDialog(i+1 +" ---Enter data");
{
if (oF.exists()== true )
{
oF.delete();
System.
out.print("File deleted ");
}
else
{
System.
out.print("file does not exist ");
}
}
}
 
JOptionPane.showMessageDialog(
null, "over");
}
public static String cCheck_File_Array(String aArr[] , String sPattern)
{
int i;
String sRes=
"";
//String spattern =sPattern; //"(.*)(output)(.*)(xls)";
Pattern oPattern = Pattern.compile(sPattern);
for (i=0 ; i <= aArr.length-1 ; i++ )
{
Matcher oMatcher = oPattern.matcher(aArr[i]);
if (oMatcher.find( )== true)
{
System.
out.println(aArr[i]+"--matches");
sRes=sRes+
","+i;
}
}
return sRes;
}
public static boolean cString_match(String sStr, String sPattern)
{
//String sRes="";
Pattern oPattern = Pattern.compile(sPattern);
Matcher oMatcher = oPattern.matcher(sStr);
if (oMatcher.find( )== true)
{
System.
out.println(sStr+"--matches");
return true;
}
else
{
System.
out.println(sStr +"--no matches");
return false;
}
}
}

'---------------------------------------------------------------------------------Formatted

import
java.io.File;

import
java.io.IOException;
//import java.util.Locale;
import
javax.swing.JOptionPane;
import
jxl.*;
import
jxl.write.*;
import
jxl.write.Number;
import
jxl.write.biff.RowsExceededException;
import
jxl.read.biff.BiffException;
//import jxl.write.WritableSheet;
//import jxl.write.WritableWorkbook;
//import jxl.write.*;
import
java.util.regex.Matcher;
import
java.util.regex.Pattern;
 
 

public class Framework
{
public static void main(String[] args) throws BiffException, IOException, RowsExceededException, WriteException
{
String sDir = JOptionPane.showInputDialog("Enter any Directory");
String sTemp;
String pattern = "(.*)(output)(.*)(xls)";
int i;
//int iSize=Integer.parseInt(JOptionPane.showInputDialog("Enter array size"));
File oDir = new File(sDir);
String[] aFiles = oDir.list();
for (i=0 ; i <= aFiles.length-1 ; i++ )
{
//sTemp=aFiles[i];
File oF=new File(sDir+"\\"+(aFiles[i]));
if (cString_match(oF.getName(),pattern) == true ) //aArr[i]=JOptionPane.showInputDialog(i+1 +" ---Enter data");
{
if (oF.exists()== true )
{
oF.delete();
System.out.print("File deleted ");
}
else
{
System.out.print("file does not exist ");
}
}
}

JOptionPane.showMessageDialog(null, "over");
}
public static String cCheck_File_Array(String aArr[] , String sPattern)
{
int i;
String sRes="";
//String spattern =sPattern; //"(.*)(output)(.*)(xls)";
Pattern oPattern = Pattern.compile(sPattern);
for (i=0 ; i <= aArr.length-1 ; i++ )
{
Matcher oMatcher = oPattern.matcher(aArr[i]);
if (oMatcher.find( )== true)
{
System.out.println(aArr[i]+"--matches");
sRes=sRes+","+i;
}
}
return sRes;
}
public static boolean cString_match(String sStr, String sPattern)
{
//String sRes="";
Pattern oPattern = Pattern.compile(sPattern);
Matcher oMatcher = oPattern.matcher(sStr);
if (oMatcher.find( )== true)
{
System.out.println(sStr+"--matches");
return true;
}
else
{
System.out.println(sStr +"--no matches");
return false;
}
}
}

Selenium: To write data to a new spread sheet

To write data to a new spread sheet



import
java.io.File;
import
java.io.IOException;
import javax.swing.JOptionPane;
import
jxl.*;
import
jxl.write.*;
import
jxl.write.Number;
import
jxl.write.biff.RowsExceededException;
import
jxl.read.biff.BiffException;
 
public
class Framework
{
public static void main(String[] args) throws BiffException, IOException, RowsExceededException, WriteException
{
string numString = JOptionPane.showInputDialog("Enter a path");
WritableWorkbook workbook = Workbook.createWorkbook(
new File(numString )); //"D:\\output.xls"
WritableSheet sheet = workbook.createSheet(
"First Sheet", 0);
Label label =
new Label(0, 2, "some data");//(col,row,data) row col starts from 0
sheet.addCell(label);
// If data is string
Number number =
new Number(3, 4, 3.1459);//(col,row,data) row col starts from 0
sheet.addCell(number);
// If data is a number
workbook.write();
workbook.close();
}
}
//--------------------------------------------------------------------------------------------------

import
java.io.File;

import
java.io.IOException;
import javax.swing.JOptionPane;
import
jxl.*;
import
jxl.write.*;
import
jxl.write.Number;
import
jxl.write.biff.RowsExceededException;
import
jxl.read.biff.BiffException;
 
public
class Framework
{
public static void main(String[] args) throws BiffException, IOException, RowsExceededException, WriteException
{
string numString = JOptionPane.showInputDialog("Enter a path");
WritableWorkbook workbook = Workbook.createWorkbook(new File(numString )); //"D:\\output.xls"

WritableSheet sheet = workbook.createSheet("First Sheet", 0);
Label label = new Label(0, 2, "some data");//(col,row,data) row col starts from 0
sheet.addCell(label);
// If data is string
Number number = new Number(3, 4, 3.1459);//(col,row,data) row col starts from 0
sheet.addCell(number);
// If data is a number
workbook.write();
workbook.close();
}
}

Selenium: To display all the Rows and Columns in an excel sheet

To display all the rows and columns inside Spreadsheet

//All the related API and JARS should be added (Read previous program ) for more details




import
java.io.File;
import
java.io.IOException;
//import java.util.Locale;
//import javax.swing.JOptionPane;
import
jxl.*;
import
jxl.read.biff.BiffException;
//import jxl.write.*;
 
public
class Framework
{
public static void main(String[] args) throws BiffException, IOException
{
String sPath=JOptionPane.showInputDialog("Enter excel Path");//"D:\\Selenium\\sample.xls"
Workbook workbook = Workbook.getWorkbook(
new File ("sPath"));//
Sheet sheet = workbook.getSheet(0); //workbook.getSheet("Sheet1")
for (int i = 0; i < sheet.getRows(); i++)
{
for (int j = 0; j < sheet.getColumns(); j++)
{
Cell cell = sheet.getCell(j,i);
//getcell(col,row)
System.
out.print(cell.getContents()+" ");
}
System.
out.println("");// or System.out.print("\n");
}
workbook.close();
}
}

Monday, February 18, 2013

Selenium : JS Alert handling using "Try"and "Catch"

The following code does the same job as the previous except that it uses TRY and CATCH to resolve the issue.


import
org.openqa.selenium.Alert;


import
org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.firefox.FirefoxDriver;
import
org.openqa.selenium.support.events.EventFiringWebDriver;
import
org.openqa.selenium.support.ui.ExpectedConditions;
import
org.openqa.selenium.support.ui.WebDriverWait;
 
public
class handle_javascript_err {
 
public static void main(String[] args) throws InterruptedException
{
WebDriver driver=
new FirefoxDriver();
EventFiringWebDriver d=
new EventFiringWebDriver(driver);
driver.get(
"http://www.w3schools.com/js/tryit.asp?filename=tryjs_intro_validate");
driver.switchTo().frame(
"viewIFRAME");
driver.findElement(By.id(
"demo")).sendKeys("abc");
driver.findElement(By.xpath(
"//button[text()='Click Me!']")).click();
try
{
System.out.println( driver.switchTo().alert().getText()+" --- Alert is present");
driver.switchTo().alert().accept();
}
catch (org.openqa.selenium.UnhandledAlertException e)
{
System.
out.println("not present");
}
Thread.sleep(1000);
driver.quit();
}
}

Selenium : Handling Alert messages from Javascript

 The Following code is used handle Alert message in webpages from javascript.


Refer - http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html

/* The following code goes to http://www.w3schools.com/js/tryit.asp?filename=tryjs_intro_validate" , where a JS Alert is popped whenever a user types a non-numeric value to message box */



import

org.openqa.selenium.Alert;
import
org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.firefox.FirefoxDriver;
import
org.openqa.selenium.support.events.EventFiringWebDriver;
import
org.openqa.selenium.support.ui.ExpectedConditions;
import
org.openqa.selenium.support.ui.WebDriverWait;
 
public
class handle_javascript_err {
public static void main(String[] args) throws InterruptedException
{
WebDriver driver=
new FirefoxDriver();
EventFiringWebDriver d=
new EventFiringWebDriver(driver);
driver.get(
"http://www.w3schools.com/js/tryit.asp?filename=tryjs_intro_validate");
driver.switchTo().frame(
"viewIFRAME");
driver.findElement(By.id(
"demo")).sendKeys("abc");
driver.findElement(By.xpath(
"//button[text()='Click Me!']")).click();
WebDriverWait wait =
new WebDriverWait(driver, 300); /*timeout in seconds*/
if(wait.until(ExpectedConditions.alertIsPresent())==null)
{
System.
out.println("alert was not present");
}
else
{
System.
out.println("alert was present");
driver.switchTo().alert().accept();
}
Thread.sleep(5000);
driver.findElement(By.id(
"demo")).sendKeys("abcfff");
driver.quit();
}
}

Selenium : Printing name in the form of a triangle

Printing name in the form of a triangle




import javax.swing.JOptionPane; 
import javax.swing.Spring;
import org.apache.commons.lang3.StringUtils;

public class Triangle
{


 public static void main(String[] args)
 {
  String res="";
  String fin="";
  String a=JOptionPane.showInputDialog(null,"What is your name ?"); 

  if ( a.length() % 2 != 0)
  {
   a=a+"_";
  }


  for (int len=1 ; len<= a.length() ; len++)
  {
   res=StringUtils.leftPad(a.substring(0, len), a.length())+"\n";
   fin=fin+res;
  }
  JOptionPane.showMessageDialog(null, fin);

 }

}



Selenium : Check Object visibility.

To check whether the object is visible using the previous concept



import java.sql.Driver;
import java.util.List;
import javax.swing.JOptionPane;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.events.EventFiringWebDriver;
public class Google
{

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

  WebDriver driver= new FirefoxDriver();
  EventFiringWebDriver d=new EventFiringWebDriver(driver);

  d.get("http://www.google.co.in/");
  WebElement box = d.findElement(By.id("gsr"));//id("mngb"));
  List names =box.findElements(By.tagName("button"));
  JOptionPane.showMessageDialog(null, "names.size()="+names.size());

  for (int i=0 ; i<names.size();i++ )//(WebElement) names.get(i)).getText() != null ||
  {
 
   if ( ((WebElement) names.get(i)).isDisplayed() == true  )//(((WebElement) names.get(i)).getText().length()>2) //box.findElement(By.xpath("xpathExpression")).//isDisplayed()
   {
    System.out.println(((WebElement) names.get(i)).getText()+" "+i);
   }
 
   else if (((WebElement) names.get(i)).isDisplayed() == false  )//(box.findElement(By.tagName("button")).isDisplayed() == false ) //(((WebElement) names.get(i)).getText().length()<=2)
   {
    System.out.println(((WebElement) names.get(i)).getAttribute("id")+"---Not displayed "+i);
   }
 
 
  }
  d.quit();

 }
}


//for (int i=0 ; i< names.size(); i++)
//{
// frnd=names.get(i).getText();
// //JOptionPane.showMessageDialog(null, "hi");
// System.out.println( ((WebElement) names.get(i)).getText());
//}
//JOptionPane.showMessageDialog(null, a);
//Thread.sleep(5000L);

Selenium: To find all the buttons existing in "Googe.com" Homepage

The below code fetches string present inside all the buttons present inside "Google.com" Home page.

/* There is a peculiar scenarion I encountered while working this scenario, where the buttons actually present is 2 but we get totla of 3 buttons by running the code -- We figured out what the button was , hope u'll find too */

import
java.util.List;
import
javax.swing.JOptionPane;
import
org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.firefox.FirefoxDriver;
import
org.openqa.selenium.support.events.EventFiringWebDriver;
public
class Google
{
public static void main(String[] args) throws InterruptedException
{
String frnd;
WebDriver driver=
new FirefoxDriver();
EventFiringWebDriver d=
new EventFiringWebDriver(driver);
d.get(
"http://www.google.co.in/");
WebElement box = d.findElement(By.id(
"gsr"));//id("mngb"));
List names =box.findElements(By.tagName(
"button"));
JOptionPane.showMessageDialog(
null, "names.size()="+names.size());
for (int i=0 ; i<names.size();i++ )//(WebElement) names.get(i)).getText() != null ||
{
if (((WebElement) names.get(i)).getText().length()>2)
{
System.
out.println(((WebElement) names.get(i)).getText()+" "+i);
}
else if (((WebElement) names.get(i)).getText()== " ")
{
System.
out.println("---CONTAINS empty Space");
}
else if (((WebElement) names.get(i)).getText()==null)
{
System.
out.println("Contains null button");
}
else if (((WebElement) names.get(i)).getText().length()<=2)
{
System.
out.println(((WebElement) names.get(i)).getAttribute("id")+"---"+i);
}
}
d.quit();
}
}
 
 
//for (int i=0 ; i< names.size(); i++)
//{
// frnd=names.get(i).getText();
// //JOptionPane.showMessageDialog(null, "hi");
// System.out.println( ((WebElement) names.get(i)).getText());
//}
//JOptionPane.showMessageDialog(null, a);
//Thread.sleep(5000L);
 
 

Selenium : Ways to Identify objects

The Following Example use Parent and Child object concept to capture a particular object.Though the objective can be realised much simpler i have followed this method for the understanding of the concept .

//Example of Google homepage

/*Class to detect Google Search button ,using ParentObject ,
* findElement and findElements concepts
*/
import

java.util.List;
import
javax.swing.JOptionPane;
import
org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.firefox.FirefoxDriver;
import
org.openqa.selenium.support.events.EventFiringWebDriver;
public
class Test
{
public
static void main(String[] args) throws InterruptedException
{
WebDriver driver= new
FirefoxDriver();
EventFiringWebDriver d=new
EventFiringWebDriver(driver);
d.get("http://www.google.co.in/");
//WebElement box = d.findElement(By.xpath("//div[@id='als']"));
WebElement box = d.findElement(By.id("mngb"));
//List names =box.findElements(By.id("gbqfba"));
WebElement names =box.findElement(By.id("gbqfba"));
System.out
.println(names.getText());
//JOptionPane.showMessageDialog(null, "names.size()="+names.size());

box = d.findElement(By.className("jsb"));//id("mngb"));
names =box.findElement(By.className("gbqfba"));
System.out
.println(names.getText()); 

box = d.findElement(By.id("gsr"));//id("mngb"));
names =box.findElement(By.name("btnK"));//id("gbqfba"));
System.out
.println(names.getText());

box = d.findElement(By.xpath("//*[@id='body']/center/div[2]"));//id("mngb"));
names =box.findElement(By.xpath("//*[@id='gbqfba']"));//id("gbqfba"));
System.out
.println(names.getText());
 
d.quit();
}
}
 
 
 
 
 
 
 
 

Friday, February 15, 2013

Selenium Cheat Sheet --

Sample Program to demonstrate parameterization using text file in Eclipse (Selenium WebDriver)

/* Program to demo parameterization using text file */
/*Text File is stored in path  "D:\\Selenium\\Programs\\Class\\Parameter.txt " */
/*Data inside text is in the format "2,3,4" -meaning to click links at the bottom 2,3,4 form the website "http://www.rtt.ag/en"   */


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;

public class Para
{

 public static void main(String[] args) throws IOException, InterruptedException
 {
  String strLine;
  //int iTemp;
  WebDriver driver = new FirefoxDriver();

  driver.get("http://www.rtt.ag/en/");
  //driver.manage().window().maximize();


        FileInputStream fstream = new FileInputStream("D:\\Selenium\\Programs\\Class\\Parameter.txt");
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
      
        while ((strLine = br.readLine()) != null )
        {
            strLine = strLine.trim();
            //if ((strLine.length()!=0) && (strLine.charAt(0)!='#')) {
                String[] students = strLine.split(",");
                //for (int i=0 ; i<students.length-1 ; i++ )
                for (int i=0 ; i<students.length ; i++ )
                {
                 //driver.findElement(By.xpath("//*[@id='footer']/div[1]/div[2]/div/div[1]/ul/li["+students[i]+"]/a")).
                 driver.findElement(By.xpath("//*[@id='footer']/div[1]/div[2]/div/div[1]/ul/li["+students[i]+"]/a")).click();
                 Thread.sleep(1000);
               
                }      
               
        }  
        driver.quit();
    
 }
}

Configuring Eclipse (Helios) for Selenium WebDriver

Configuring Eclipse (Helios) for Selenium WebDriver

  1.  Download Selenium WebDriver From SeleniumHQ.com under "Selenium Client & WebDriver Language Bindings "
  2.  click on  Java  download file. 
  3. Unzip it to find Jar files.
  4. Goto Eclipse website   http://www.eclipse.org/helios/ 
  5. Download "Eclipse IDE for Java EE Developers".
  6.    Unzip it .

 The Eclipse is a poratble Exe meaning no installation is required . Double click on the exe file to open eclipse..

 To Config Eclipse for Selenium follow the below procedure .

  •      Open Eclipse .
  •      Onthe top most parent folder in Rt Click --Project Explorer>Properties >java Build Path >Select "Libraries" Tab
  • Click Add External JARS>Now select all the Selenium Webdriver Downloaded from SeleniumHQ *
The Eclipse is configured for Selenium.



Refer : 
 http://catchbug.blogspot.in/2013/02/configuring-eclipse-helios-for-selenium.html
http://catchbug.blogspot.in/2013/02/integrating-testng-with-eclipse.html

Input and Outbox in Eclipse (Selenium WebDriver)

Program to Retrieve Data From the User using Input Box and Output the same using Output Box

//Following Code written in Eclipse -Helios

import

javax.swing.JOptionPane;
public
class Input_box
{
public static void main(String[] args)
{
String a=JOptionPane.showInputDialog(
null,"What is your name ?");
JOptionPane.showMessageDialog(
null, a);
}
}

Wednesday, February 13, 2013

Descriptive Programming in CODEDUI Visual Studio Ultimate 2010

Descriptive Programming in CODEDUI Visual Studio Ultimate 2010

Code to press button "3" from the Calculator UI of Windows XP.


1. Open Visual Studio 2010 > Select New project > Select "Test Project" from Visual C# ,Test
   You should be able to see a Blank workspace created ,
2. On your right side in properties you will have Unittest1  Created .Select that file from the tree right click and delete.

3. Click on New Template >Select Coded UI>Ok

4.Delete any pre-exsisting code from the workspace and Copy the below and paste in the workspace.

Lets discuss the code :

//calculator should already be open
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows.Input;
using System.Windows.Forms;
using System.Drawing;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UITest.Extension;
using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
using System.Threading;

///////////////////////// MAIN CLASS
[CodedUITest]
public class CodedUITest1
{
    private UICalculatorWindow mUICalculatorWindow;//Object Declaration ---1
    public CodedUITest1()//Constructor-----2
    {
    }
    [TestMethod]
    public void CodedUITestMethod1() //Similar to Main ()
    {
        Thread.Sleep(1000); /*//Declared simply ,can be commented ([using System.Threading;])*/
        this.UICalculatorWindow.UIItem3Window.UIItem3Button.SearchProperties[WinButton.PropertyNames.Name] = "3";
  

        Mouse.Click(this.UICalculatorWindow.UIItem3Window.UIItem3Button, new Point(18, 18));
    }
    public UICalculatorWindow UICalculatorWindow //Setting Property for Main Window -----4 
    {
        get
        {
            mUICalculatorWindow = new UICalculatorWindow();
            return mUICalculatorWindow;
        }
    }
}
 ///////////////////////////////////////////////////Class 2

public class UICalculatorWindow : WinWindow //Parent Window
{
    private UIItem3Window mUIItem3Window;/*
Child Window Object*/
    public UICalculatorWindow()  //Constructor for Main Window  
    {
        this.SearchProperties[WinWindow.PropertyNames.Name] = "Calculator";
        this.SearchProperties[WinWindow.PropertyNames.ClassName] = "SciCalc";
    }
    public UIItem3Window UIItem3Window //Property for Child Window
    {
        get
        {
            mUIItem3Window = new UIItem3Window(this);
            return mUIItem3Window;
        }
    }
}
 ////////////////////////////////////////////////////////////////////Class 3

public class UIItem3Window : WinWindow  /*Child Window Class ,inhereting WinWindow properties */
{
    private WinButton mUIItem3Button;//Object Declaration
    public UIItem3Window(UITestControl searchLimitContainer) //Constructor
    {
        this.SearchProperties[WinWindow.PropertyNames.ControlId] = "127";// child window
    }
    public WinButton UIItem3Button  //Property For Button
    {
        get
        {
            mUIItem3Button = new WinButton(this); 
            return mUIItem3Button;
        }
    }
}
 /////////////////////////////////////////////////////////////////////////////////////////////////////END

The above code "press button 3" on the Windows XP Calculator using technique similar to descriptive programming in QTP.

1) The button 3 is actually inside 2 Windows .
  1. "UICalculatorWindow"  is the parent window
  2. "UIItem3Window"  is the child window
  3. UIItem3Button  is button "3" is present inside the child Window .
2) A seperate class has been created for parent window object and child window object whose properties has been initialised .

3)For the button object  the properties has been initialsed directly in the Main function which is ( public void CodedUITestMethod1() )
Remeber (Main Function in coded UI is "public void CodedUITestMethod1() " meaning the execution starts from there and also all the operation is written here).

4)The Logic in CUI as far as my understanding goes is something like this :
Ex : Lets say "W" is a Window and "B" is a button inside the Window "W" which we need to Click.
Therefore B is a child of W.

5) We need to create 2 Classes :-
   (1) is the Main Class (i.e.,  public void CodedUITestMethod1() ) and (2) is the Object Definition for the parent Class in our case "W" .

(1)  which is the Main Class contains
  • Declaration of Parent Window Object "W".
  • Constructor for the class
  • Initialzation of property for the button "B" and to click the button.
  • Assigning Property value to the Parent Window Object "W".
(2) is the Parent Window Object Class  contains .
  • Declaration of Parent Window Object "B".
  • Constructor for the class
  • Initialzation of "W" properties.
  • Assigning Property value to the Button Object "B".

Remember :Each Parent Class will have its child object declared inside it and Property call  for the child!!