Silk Test 2008 R 2 SP 1 Silk

  • Slides: 42
Download presentation
Silk. Test 2008 R 2 SP 1: Silk 4 J Introduction

Silk. Test 2008 R 2 SP 1: Silk 4 J Introduction

What is Silk 4 J? • Silk 4 J enables you to create functional

What is Silk 4 J? • Silk 4 J enables you to create functional tests using the Java programming language. • Silk 4 J provides a Java runtime library that includes test classes for all the classes that Silk 4 J 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 Silk 4 J against other testing frameworks, such as Test. NG Copyright © 2008 Borland Software Corporation. Confidential 2

What kind of applications can be tested? • Silk 4 J allows a user

What kind of applications can be tested? • Silk 4 J 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 x. Browser (IE 6 & IE 7) Copyright © 2008 Borland Software Corporation. Confidential 3

Testing methodology? • Silk 4 J implements the newly introduced Dynamic Object Recognition (DOR)

Testing methodology? • Silk 4 J implements the newly introduced Dynamic Object Recognition (DOR) methodology for creating tests • DOR allows the user to find and indentify controls using XPath queries • Silk 4 J provides 2 methods that can be used for finding and identifying controls: • Find. All • It is currently only possible to manually script tests with Silk 4 J, the recording of actions is currently not possible Copyright © 2008 Borland Software Corporation. Confidential 4

Resources • The Silk 4 J User Guide can be accessed through the Eclipse

Resources • The Silk 4 J User Guide can be accessed through the Eclipse IDE • Help Contents • The User Guide provides a useful introduction into many of the concepts behind Silk 4 J, 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 Silk 4 J framework Copyright © 2008 Borland Software Corporation. Confidential 5

Silk 4 J Help Copyright © 2008 Borland Software Corporation. Confidential 6

Silk 4 J Help Copyright © 2008 Borland Software Corporation. Confidential 6

Silk 4 J Introduction: Creating a Silk 4 J Project

Silk 4 J Introduction: Creating a Silk 4 J Project

Creating a Silk 4 J Project • Open the Silk 4 J IDE or

Creating a Silk 4 J Project • Open the Silk 4 J IDE or the Eclipse environment in which the Silk 4 J plug-in was installed • When opened, to create a new project simply perform the following menu selects: • File New Project Copyright © 2008 Borland Software Corporation. Confidential 8

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

Project Wizard • You will then encounter the “New Project” dialog • Select, Silk 4 J Project • Click “Next” after making the above selection Copyright © 2008 Borland Software Corporation. Confidential 9

Project Wizard, cont’d • Assign the Silk 4 J project a name and click

Project Wizard, cont’d • Assign the Silk 4 J project a name and click “Next” Copyright © 2008 Borland Software Corporation. Confidential 10

Project Wizard, cont’d • On the following dialog there is little more to do,

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 Copyright © 2008 Borland Software Corporation. Confidential 11

Silk 4 J Project Created • You should now find that our newly created

Silk 4 J Project Created • You should now find that our newly created Silk 4 J project is displayed in the “Package Explorer” view • We can now proceed and create a “Base State” and begin scripting our tests Copyright © 2008 Borland Software Corporation. Confidential 12

Silk 4 J Introduction: Creating a Base State

Silk 4 J Introduction: Creating a Base State

Creating a Base State • Before we begin, lets ensure that the Open Agent

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 Silk. Test Copyright © 2008 Borland Software Corporation. Confidential 14

Creating a Base State: The AUT Copyright © 2008 Borland Software Corporation. Confidential 15

Creating a Base State: The AUT Copyright © 2008 Borland Software Corporation. Confidential 15

Creating a Base State, cont’d • Silk 4 J provide a wizard for creating

Creating a Base State, cont’d • Silk 4 J provide a wizard for creating Base States • Simply named “Silk 4 J Base State” • To access this wizard: • Right click on the “src” folder of your project • Select New Other Copyright © 2008 Borland Software Corporation. Confidential 16

Creating a Base State, cont’d • From the new dialog, we can now select

Creating a Base State, cont’d • From the new dialog, we can now select the “Silk 4 J Base State” option • Click “Next” to continue Copyright © 2008 Borland Software Corporation. Confidential 17

Creating a Base State, cont’d • We are then presented with the following dialog:

Creating a Base State, cont’d • We are then presented with the following dialog: Copyright © 2008 Borland Software Corporation. Confidential 18

Creating a Base State, cont’d • As seen in the above dialog, the details

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 Silk 4 J 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 “base. State” • This method is automatically executed before each Silk 4 J test • Click “Next” after providing the required details Copyright © 2008 Borland Software Corporation. Confidential 19

Creating a Base State, cont’d • The Base State wizard will then ask the

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 Copyright © 2008 Borland Software Corporation. Confidential 20

Creating a Base State, cont’d • The “Select an Application to test” dialog Copyright

Creating a Base State, cont’d • The “Select an Application to test” dialog Copyright © 2008 Borland Software Corporation. Confidential 21

Creating a Base State, cont’d • To specify a window locator, click the “…”

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 “Flex. Application” window locator as I wish to test the Flex application solely Copyright © 2008 Borland Software Corporation. Confidential 22

Creating a Base State, cont’d • The Window Locator dialog: Copyright © 2008 Borland

Creating a Base State, cont’d • The Window Locator dialog: Copyright © 2008 Borland Software Corporation. Confidential 23

Creating a Base State, cont’d • Click “OK”, followed by “Finish” • The Base

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 Copyright © 2008 Borland Software Corporation. Confidential 24

Creating a Base State, cont’d • As can been seen from the code skeleton,

Creating a Base State, cont’d • As can been seen from the code skeleton, Silk 4 J leverages against JUnit. • The “base. State” method, uses the “@Before” JUnit annotation. This annotation ensures that the “base. State” method is executed prior to each test. • The “base. State” method is responsible for starting and hooking (i. e. loading the Tech Domains) the AUT Copyright © 2008 Borland Software Corporation. Confidential 25

Silk 4 J Introduction: Creating a Silk 4 J test

Silk 4 J Introduction: Creating a Silk 4 J test

Creating a Silk 4 J test • As seen in the previous section, the

Creating a Silk 4 J test • As seen in the previous section, the Base State wizard created a test method for us • In this instance the test method “check. For. Flex” 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 Flex. Application class @Test public void check. For. Flex() { //Verifies that the Flex application exists main. Window. exists(); } Copyright © 2008 Borland Software Corporation. Confidential 27

Creating a Silk 4 J test, cont’d • Now if we were to execute

Creating a Silk 4 J 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 “assert. True” • The “assert. True” method allows the user to ensure that a certain statement or call always returns true and if not, the JUnit framework will cause the Silk 4 J test to fail Copyright © 2008 Borland Software Corporation. Confidential 28

Creating a Silk 4 J test, cont’d • We can now expand on our

Creating a Silk 4 J test, cont’d • We can now expand on our original test, using the previously stated class and method @Test public void check. For. Flex() { //Verifies that the Flex application exists Assert. assert. True(main. Window. exists()); } • And we now have a basic Silk 4 J 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 As JUnit Test Copyright © 2008 Borland Software Corporation. Confidential 29

Creating a Silk 4 J test, cont’d • So perhaps our last test was

Creating a Silk 4 J 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 Silk 4 J interaction Copyright © 2008 Borland Software Corporation. Confidential 30

Creating a Silk 4 J test, cont’d Copyright © 2008 Borland Software Corporation. Confidential

Creating a Silk 4 J test, cont’d Copyright © 2008 Borland Software Corporation. Confidential 31

Creating a Silk 4 J test, cont’d • Ok, so how do we go

Creating a Silk 4 J test, cont’d • Ok, so how do we go about automating these actions? • Firstly, we need to create a new test method @Test public void expand. Tree() { } • We know that we want to interact with the tree control, therefore we must find it @Test public void expand. Tree() { //Find the Flex. Tree control Flex. Tree my. Flex. Tree = (Flex. Tree)main. Window. find( “locator”); } • We can see from the above “find” statement, we need to provide a string locator which now introduces us to the Silk 4 J Spy Copyright © 2008 Borland Software Corporation. Confidential 32

Creating a Silk 4 J test, cont’d • We use the Silk 4 J

Creating a Silk 4 J test, cont’d • We use the Silk 4 J spy to determine the window locator string for a given control • The Silk 4 J Spy is generally located at the bottom of the Eclipse IDE • To use the Silk 4 J 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” Copyright © 2008 Borland Software Corporation. Confidential 33

Creating a Silk 4 J test, cont’d • If we now bring up the

Creating a Silk 4 J test, cont’d • If we now bring up the Eclipse IDE, we can now see that the Silk 4 J 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: @Test public void expand. Tree() { //Find the Flex. Tree control Flex. Tree my. Flex. Tree = (Flex. Tree)main. Window. find( ". //Flex. Tree[@caption='comp. Lib. Tree' and @class. Name='mx. controls. Tree' and @windowid='comp. Lib. Tree']"); } Copyright © 2008 Borland Software Corporation. Confidential 34

Creating a Silk 4 J test, cont’d • So I have found my tree

Creating a Silk 4 J test, cont’d • So I have found my tree control, now I want to automate some actions • Lets try to expand some nodes @Test public void expand. Tree() { //Find the Flex. Tree control Flex. Tree my. Flex. Tree = (Flex. Tree)main. Window. find( ". //Flex. Tree[@caption='comp. Lib. Tree' and @class. Name='mx. controls. Tree' and @windowid='comp. Lib. Tree']"); //Expand the tree my. Flex. Tree. expand(“Visual Components”); my. Flex. Tree. expand(“Visual Components>Button Controls” ); } • Note that each tree node has to be expanded individually • An exception would be encountered otherwise, leading to a test failure Copyright © 2008 Borland Software Corporation. Confidential 35

Creating a Silk 4 J test, cont’d • So we’ve expanded some nodes, now

Creating a Silk 4 J test, cont’d • So we’ve expanded some nodes, now we need to select a node: @Test public void expand. Tree() { //Find the Flex. Tree control Flex. Tree my. Flex. Tree = (Flex. Tree)main. Window. find( ". //Flex. Tree[@caption='comp. Lib. Tree' and @class. Name='mx. controls. Tree' and @windowid='comp. Lib. Tree']"); //Expand the tree my. Flex. Tree. expand(“Visual Components”); my. Flex. Tree. expand(“Visual Components>Button Controls” ); //Select the “Button” node my. Flex. Tree. select(“ Visual Components>Button Controls>Button”); } • So we can now see that Silk 4 J will drive the Open Agent to expand some tree nodes and select the “Button” node Copyright © 2008 Borland Software Corporation. Confidential 36

Creating a Silk 4 J test, cont’d • So our test at present should

Creating a Silk 4 J 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 Copyright © 2008 Borland Software Corporation. Confidential 37

Creating a Silk 4 J test, cont’d • We must therefore return to the

Creating a Silk 4 J test, cont’d • We must therefore return to the Silk 4 J 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: Copyright © 2008 Borland Software Corporation. Confidential 38

Creating a Silk 4 J test, cont’d @Test public void expand. Tree() { //Find

Creating a Silk 4 J test, cont’d @Test public void expand. Tree() { //Find the Flex. Tree control Flex. Tree my. Flex. Tree = (Flex. Tree)main. Window. find( ". //Flex. Tree[@caption='comp. Lib. Tree' and @class. Name='mx. controls. Tree' and @windowid='comp. Lib. Tree']"); //Expand the tree my. Flex. Tree. expand(“Visual Components”); my. Flex. Tree. expand(“Visual Components>Button Controls” ); //Select the “Button” node my. Flex. Tree. select(“ Visual Components>Button Controls>Button”); //Search for the "With Icon" Flex Button Flex. Button with. Icon = (Flex. Button)main. Window. find( ". //Flex. Button[@caption='Button with Icon‘ and @class. Name='mx. controls. Button' and @windowid='icon. Button']"); //Verify that our test has opened the correct item and the button exists Assert. assert. True(with. Icon. exists ()); //Click the button with. Icon. click(); } Copyright © 2008 Borland Software Corporation. Confidential 39

Creating a Silk 4 J test, cont’d • And this is how it looks

Creating a Silk 4 J test, cont’d • And this is how it looks within the Eclipse IDE Copyright © 2008 Borland Software Corporation. Confidential 40

Creating a Silk 4 J test, cont’d • We can now execute our two

Creating a Silk 4 J 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 Copyright © 2008 Borland Software Corporation. Confidential 41

And Finally • It is up to you, the user, to now create your

And Finally • It is up to you, the user, to now create your own Silk 4 J tests to automate your AUT Copyright © 2008 Borland Software Corporation. Confidential 42