Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional."— Presentation transcript:

1 SilkTest 2008 R2 SP1: Silk4J Introduction

2 ConfidentialCopyright © 2008 Borland Software Corporation. 2 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

3 ConfidentialCopyright © 2008 Borland Software Corporation. 3 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)

4 ConfidentialCopyright © 2008 Borland Software Corporation. 4 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

5 ConfidentialCopyright © 2008 Borland Software Corporation. 5 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

6 ConfidentialCopyright © 2008 Borland Software Corporation. 6 Silk4J Help

7 Silk4J Introduction: Creating a Silk4J Project

8 ConfidentialCopyright © 2008 Borland Software Corporation. 8 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

9 ConfidentialCopyright © 2008 Borland Software Corporation. 9 Project Wizard You will then encounter the “New Project” dialog Select, Silk4J  Silk4J Project Click “Next” after making the above selection

10 ConfidentialCopyright © 2008 Borland Software Corporation. 10 Project Wizard, cont’d Assign the Silk4J project a name and click “Next”

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

12 ConfidentialCopyright © 2008 Borland Software Corporation. 12 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

13 Silk4J Introduction: Creating a Base State

14 ConfidentialCopyright © 2008 Borland Software Corporation. 14 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

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

16 ConfidentialCopyright © 2008 Borland Software Corporation. 16 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

17 ConfidentialCopyright © 2008 Borland Software Corporation. 17 Creating a Base State, cont’d From the new dialog, we can now select the “Silk4J Base State” option Click “Next” to continue

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

19 ConfidentialCopyright © 2008 Borland Software Corporation. 19 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

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

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

22 ConfidentialCopyright © 2008 Borland Software Corporation. 22 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

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

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

25 ConfidentialCopyright © 2008 Borland Software Corporation. 25 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

26 Silk4J Introduction: Creating a Silk4J test

27 ConfidentialCopyright © 2008 Borland Software Corporation. 27 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 @Test public void checkForFlex() { //Verifies that the Flex application exists mainWindow.exists(); }

28 ConfidentialCopyright © 2008 Borland Software Corporation. 28 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

29 ConfidentialCopyright © 2008 Borland Software Corporation. 29 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 @Test public void checkForFlex() { //Verifies that the Flex application exists Assert.assertTrue(mainWindow.exists()); }

30 ConfidentialCopyright © 2008 Borland Software Corporation. 30 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

31 ConfidentialCopyright © 2008 Borland Software Corporation. 31 Creating a Silk4J test, cont’d

32 ConfidentialCopyright © 2008 Borland Software Corporation. 32 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 @Test public void expandTree() { } @Test public void expandTree() { //Find the FlexTree control FlexTree myFlexTree = (FlexTree)mainWindow.find(“locator”); }

33 ConfidentialCopyright © 2008 Borland Software Corporation. 33 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”

34 ConfidentialCopyright © 2008 Borland Software Corporation. 34 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: @Test public void expandTree() { //Find the FlexTree control FlexTree myFlexTree = (FlexTree)mainWindow.find(".//FlexTree[@caption='compLibTree' and @className='mx.controls.Tree' and @windowid='compLibTree']"); }

35 ConfidentialCopyright © 2008 Borland Software Corporation. 35 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 @Test public void expandTree() { //Find the FlexTree control FlexTree myFlexTree = (FlexTree)mainWindow.find(".//FlexTree[@caption='compLibTree' and @className='mx.controls.Tree' and @windowid='compLibTree']"); //Expand the tree myFlexTree.expand(“Visual Components”); myFlexTree.expand(“Visual Components>Button Controls”); }

36 ConfidentialCopyright © 2008 Borland Software Corporation. 36 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 @Test public void expandTree() { //Find the FlexTree control FlexTree myFlexTree = (FlexTree)mainWindow.find(".//FlexTree[@caption='compLibTree' and @className='mx.controls.Tree' and @windowid='compLibTree']"); //Expand the tree myFlexTree.expand(“Visual Components”); myFlexTree.expand(“Visual Components>Button Controls”); //Select the “Button” node myFlexTree.select(“ Visual Components>Button Controls>Button ”); }

37 ConfidentialCopyright © 2008 Borland Software Corporation. 37 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

38 ConfidentialCopyright © 2008 Borland Software Corporation. 38 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:

39 ConfidentialCopyright © 2008 Borland Software Corporation. 39 Creating a Silk4J test, cont’d @Test public void expandTree() { //Find the FlexTree control FlexTree myFlexTree = (FlexTree)mainWindow.find(".//FlexTree[@caption='compLibTree' and @className='mx.controls.Tree' and @windowid='compLibTree']"); //Expand the tree myFlexTree.expand(“Visual Components”); myFlexTree.expand(“Visual Components>Button Controls”); //Select the “Button” node myFlexTree.select(“ Visual Components>Button Controls>Button ”); //Search for the "With Icon" Flex Button FlexButton 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 exists Assert.assertTrue(withIcon.exists()); //Click the button withIcon.click(); }

40 ConfidentialCopyright © 2008 Borland Software Corporation. 40 Creating a Silk4J test, cont’d And this is how it looks within the Eclipse IDE

41 ConfidentialCopyright © 2008 Borland Software Corporation. 41 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

42 ConfidentialCopyright © 2008 Borland Software Corporation. 42 And Finally It is up to you, the user, to now create your own Silk4J tests to automate your AUT


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

Similar presentations


Ads by Google