silktest 2008 r2 sp1: silk4j introduction. confidentialcopyright © 2008 borland software...

42
SilkTest 2008 R2 SP1: Silk4J Introduction

Upload: kelly-park

Post on 14-Jan-2016

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

SilkTest 2008 R2 SP1:Silk4J Introduction

Page 2: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 2Confidential

What is Silk4J?

• Silk4J enables you to create functional tests using the Java programming language.

• Silk4J provides a Java runtime library that  includes test classes for all the classes that Silk4J supports for testing.

• This runtime library is compatible with JUnit, which means you can leverage the JUnit infrastructure and run and create tests using JUnit.

• It is possible to leverage Silk4J against other testing frameworks, such as TestNG

Page 3: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 3Confidential

What kind of applications can be tested?

• Silk4J allows a user to script tests against the following kinds of application:

• Adobe Flex• Java SWT• Windows Presentation Foundation (WPF)• Windows API-based client/server applications• xBrowser (IE6 & IE7)

Page 4: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 4Confidential

Testing methodology?

• Silk4J implements the newly introduced Dynamic Object Recognition (DOR) methodology for creating tests

• DOR allows the user to find and indentify controls using XPath queries

• Silk4J provides 2 methods that can be used for finding and identifying controls:

• Find• FindAll

• It is currently only possible to manually script tests with Silk4J, the recording of actions is currently not possible

Page 5: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 5Confidential

Resources

• The Silk4J User Guide can be accessed through the Eclipse IDE

• Help Help Contents

• The User Guide provides a useful introduction into many of the concepts behind Silk4J, as well as a number of tutorials

• An API reference is also provided detailing the methods and fields available for each class provided by the Silk4J framework

Page 6: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 6Confidential

Silk4J Help

Page 7: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Silk4J Introduction:Creating a Silk4J Project

Page 8: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 8Confidential

Creating a Silk4J Project

• Open the Silk4J IDE or the Eclipse environment in which the Silk4J plug-in was installed

• When opened, to create a new project simply perform the following menu selects:

• File New Project

Page 9: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 9Confidential

Project Wizard

• You will then encounter the “New Project” dialog• Select, Silk4J Silk4J Project

• Click “Next” after making the above selection

Page 10: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 10Confidential

Project Wizard, cont’d

• Assign the Silk4J project a name and click “Next”

Page 11: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 11Confidential

Project Wizard, cont’d

• On the following dialog there is little more to do, other than click “Finish”

• You can verify that all the required libraries we included as shown below

Page 12: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 12Confidential

Silk4J Project Created

• You should now find that our newly created Silk4J project is displayed in the “Package Explorer” view

• We can now proceed and create a “Base State” and begin scripting our tests

Page 13: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Silk4J Introduction:Creating a Base State

Page 14: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 14Confidential

Creating a Base State

• Before we begin, lets ensure that the Open Agent has been started

• This can be done by clicking the Open Agent button from the toolbar displayed below

• Let us also start the application under test (AUT)• This demo will use a Flex application hosted within Internet

Explorer 7• The application is the “Flex 3.2, Flex Control Explorer with

automation” sample application provided with SilkTest

Page 15: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 15Confidential

Creating a Base State: The AUT

Page 16: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 16Confidential

Creating a Base State, cont’d

• Silk4J provide a wizard for creating Base States• Simply named “Silk4J Base State”

• To access this wizard:• Right click on the “src” folder of your project• Select New Other

Page 17: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 17Confidential

Creating a Base State, cont’d

• From the new dialog, we can now select the “Silk4J Base State” option

• Click “Next” to continue

Page 18: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 18Confidential

Creating a Base State, cont’d

• We are then presented with the following dialog:

Page 19: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 19Confidential

Creating a Base State, cont’d

• As seen in the above dialog, the details were already provided

• “Package Name”; the Java package to which you want to store your Silk4J Java Classes

• “Class Name”; the name to which you want to assign the Java Class that will contain your tests

• “Test Method”; the name to assign the test method that the Base State wizard will automatically generate

• The Base State wizard will generate a method named “baseState”

• This method is automatically executed before each Silk4J test

• Click “Next” after providing the required details

Page 20: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 20Confidential

Creating a Base State, cont’d

• The Base State wizard will then ask the user to select the AUT executable

• In this instance, it is “iexplore.exe” for Internet Explorer 7• In the next slide, we also see that the available technologies that

can be tested are also selected

• If the application was started with any command line arguments the said field will be populated with those arguments

• If you require additional arguments, these must be manually specified

• We can then use the wizard to specify a specific window to look for using the “Window Locator” field

• Generally used to select the “Main Window” for the AUT

Page 21: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 21Confidential

Creating a Base State, cont’d

• The “Select an Application to test” dialog

Page 22: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 22Confidential

Creating a Base State, cont’d

• To specify a window locator, click the “…” button on the previous dialog

• Bring up the AUT and hover your mouse over the root window press “Control + Alt”

• If you return to the Eclipse IDE, you will find a hierarchy of Window Locators that a user can choose from

• For the purposes of this demonstration I chose a “FlexApplication” window locator as I wish to test the Flex application solely

Page 23: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 23Confidential

Creating a Base State, cont’d

• The Window Locator dialog:

Page 24: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 24Confidential

Creating a Base State, cont’d

• Click “OK”, followed by “Finish”• The Base State wizard will have created a Java Class

with a basic code skeleton from which a user can work

Page 25: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 25Confidential

Creating a Base State, cont’d

• As can been seen from the code skeleton, Silk4J leverages against JUnit.

• The “baseState” method, uses the “@Before” JUnit annotation. This annotation ensures that the “baseState” method is executed prior to each test.

• The “baseState” method is responsible for starting and hooking (i.e. loading the Tech Domains) the AUT

Page 26: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Silk4J Introduction:Creating a Silk4J test

Page 27: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 27Confidential

Creating a Silk4J test

• As seen in the previous section, the Base State wizard created a test method for us

• In this instance the test method “checkForFlex” was created

• My aim for this test is to check that the Flex application exists

• To check for the existence of a control we can use the “exists” method which is inherited by the FlexApplication class

@Testpublic void checkForFlex() {

//Verifies that the Flex application existsmainWindow.exists();

}

Page 28: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 28Confidential

Creating a Silk4J test, cont’d

• Now if we were to execute the said test, it would continually pass whether the Flex application exists or not

• If we look at the exists method we can see that it returns a boolean value

• Therefore, we must leverage against the JUnit framework again and make use of the “org.junit.Assert” class and its method “assertTrue”

• The “assertTrue” method allows the user to ensure that a certain statement or call always returns true and if not, the JUnit framework will cause the Silk4J test to fail

Page 29: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 29Confidential

Creating a Silk4J test, cont’d

• We can now expand on our original test, using the previously stated class and method

• And we now have a basic Silk4J test, which can be executed to return a “Pass” or “Fail” result

• To run the Java class as a JUnit test, from the Eclipse menu bar select:

• Run Run As JUnit Test

@Testpublic void checkForFlex() {

//Verifies that the Flex application existsAssert.assertTrue(mainWindow.exists());

}

Page 30: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 30Confidential

Creating a Silk4J test, cont’d

• So perhaps our last test was a little too basic

• Let us try to automate some actions against the Flex application

• We can see that we have a tree control• Therefore I would like to expand some nodes of this tree• I would then like to select a specific tree node• I would then like to verify that the correct content was loaded via

these actions

• The screenshot on the next slide, will highlight how I want the application to look upon Silk4J interaction

Page 31: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 31Confidential

Creating a Silk4J test, cont’d

Page 32: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 32Confidential

Creating a Silk4J test, cont’d

• Ok, so how do we go about automating these actions?• Firstly, we need to create a new test method

• We know that we want to interact with the tree control, therefore we must find it

• We can see from the above “find” statement, we need to provide a string locator which now introduces us to the Silk4J Spy

@Testpublic void expandTree() {

}

@Testpublic void expandTree() {

//Find the FlexTree controlFlexTree myFlexTree = (FlexTree)mainWindow.find(“locator”);

}

Page 33: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 33Confidential

Creating a Silk4J test, cont’d

• We use the Silk4J spy to determine the window locator string for a given control

• The Silk4J Spy is generally located at the bottom of the Eclipse IDE

• To use the Silk4J Spy, click the “Resume Tracking” button and bring up the AUT

• Hover the mouse over the control of interest, in this instance the tree control and press “Control + Alt”

Page 34: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 34Confidential

Creating a Silk4J test, cont’d

• If we now bring up the Eclipse IDE, we can now see that the Silk4J Spy has captured the window locator for the control of interest

• We now replace the “locator” string in the find method with the above window locator and our method now looks like:

@Testpublic void expandTree() {

//Find the FlexTree controlFlexTree myFlexTree =

(FlexTree)mainWindow.find(".//FlexTree[@caption='compLibTree' and @className='mx.controls.Tree'

and @windowid='compLibTree']");}

Page 35: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 35Confidential

Creating a Silk4J test, cont’d

• So I have found my tree control, now I want to automate some actions

• Lets try to expand some nodes

• Note that each tree node has to be expanded individually• An exception would be encountered otherwise, leading to a test

failure

@Testpublic void expandTree() {

//Find the FlexTree controlFlexTree myFlexTree =

(FlexTree)mainWindow.find(".//FlexTree[@caption='compLibTree' and @className='mx.controls.Tree'

and @windowid='compLibTree']");//Expand the treemyFlexTree.expand(“Visual Components”);myFlexTree.expand(“Visual Components>Button Controls”);

}

Page 36: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 36Confidential

Creating a Silk4J test, cont’d

• So we’ve expanded some nodes, now we need to select a node:

• So we can now see that Silk4J will drive the Open Agent to expand some tree nodes and select the “Button” node

@Testpublic void expandTree() {

//Find the FlexTree controlFlexTree myFlexTree =

(FlexTree)mainWindow.find(".//FlexTree[@caption='compLibTree' and @className='mx.controls.Tree'

and @windowid='compLibTree']");//Expand the treemyFlexTree.expand(“Visual Components”);myFlexTree.expand(“Visual Components>Button Controls”);

//Select the “Button” nodemyFlexTree.select(“Visual Components>Button Controls>Button”);

}

Page 37: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 37Confidential

Creating a Silk4J test, cont’d

• So our test at present should click the “Button” node, which should subsequently load some button controls within the application

• So to complete our test, we need to verify that these buttons were loaded and that our scripted actions replayed successfully

• As we previously discovered the “exists” method can be used to verify that a control is present within the AUT

Page 38: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 38Confidential

Creating a Silk4J test, cont’d

• We must therefore return to the Silk4J Spy and determine the window locator for the following control

• After obtaining the window locator for the said control, we must find it within the AUT

• We know from earlier sections that we use the “find” method for this

• After verifying that the button exists, I have decided that I will also click it

• Therefore, putting all this together our final method should look like:

Page 39: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 39Confidential

Creating a Silk4J test, cont’d

@Testpublic void expandTree() {

//Find the FlexTree controlFlexTree myFlexTree =

(FlexTree)mainWindow.find(".//FlexTree[@caption='compLibTree' and @className='mx.controls.Tree'

and @windowid='compLibTree']");//Expand the treemyFlexTree.expand(“Visual Components”);myFlexTree.expand(“Visual Components>Button Controls”);

//Select the “Button” nodemyFlexTree.select(“Visual Components>Button Controls>Button”);

//Search for the "With Icon" Flex ButtonFlexButton withIcon =

(FlexButton)mainWindow.find(".//FlexButton[@caption='Button with Icon‘ and @className='mx.controls.Button'

and @windowid='iconButton']");

//Verify that our test has opened the correct item and the button existsAssert.assertTrue(withIcon.exists());

//Click the buttonwithIcon.click();

}

Page 40: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 40Confidential

Creating a Silk4J test, cont’d

• And this is how it looks within the Eclipse IDE

Page 41: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 41Confidential

Creating a Silk4J test, cont’d

• We can now execute our two test methods• On completion we should find that they have both

passed, as shown in the Eclipse IDE

Page 42: SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional

Copyright © 2008 Borland Software Corporation. 42Confidential

And Finally

• It is up to you, the user, to now create your own Silk4J tests to automate your AUT