General Discussion

General discussion on using Twist including questions and tips

This is a public Discussion Area  publicRSS

Welcome Guest

 

Log in if you have an account.

Otherwise, register for an account.

For more details, please visit the How This Site Works page.

Forums

General Discussion Recent Posts

  • Sarita Pol
    Can we access the twist properties inside the twist scenario...1
    Post posted February 1, 2012 by Sarita Pol

    I have a case where in the Login class I want to know which type of browser I am using. What is the mobile server address. What is the version of browser and other settings defined in twist.Properties

    I am using the default system web browser instantiated by the twist. Twist version is 2.4.0.12621

    Please let me know how to implement this or procedure for the same.

    Thanks,

    Sarita.

     

     

    Recent Comment (1 of 1)

  • angshuman
    Testing webservices with Twist
    Post last edited January 5, 2012 by angshuman

    The idea of this post is to demonstrate WebServices testing from Twist. While some of our customers have already been using Twist for services testing, this post will hopefully show you easy enough steps to test your WebServices while still leveraging the authoring, maintenance aspects of Twist. In this example, we will test a simple temperature converter service exposed at http://www.w3schools.com/webservices/tempconvert.asmx, which provides simple celsius to fahrenheit degrees conversion.

    Pre-requisite:

    • This example is built with Apache CXF 2.4.2, and you should download it from here (http://cxf.apache.org/download.html), and extract the archive to a local directory. Apache CXF is an open source services framework, and allows you test services over a variety of protocols such as SOAP, XML/HTTP, RESTful HTTP etc and over transports such as HTTP, JMS or JBI.
    • You should also extract the bundled example project and import it within Twist. It contains a simple Twist project testing the above mentioned service. We are going to refer some classes, configurations, build samples from the example project.


    1. Creating the project

    • Create a Twist project, with driver of your choice. For the example project, I have chosen "none". But you may as well integrate this with your chosen driver for your mixed-mode testing requirements (like use a web browser interface to place an order, and verify the transaction through a webservices call).


    2. Generating the building stubs, skeletons, and data types from WSDL.

    What we want is a simple and usable enough java interface for accessing the remote WebService. something like:

      converterService.celsiusToFahrenheit("32")

    A fair amount of boilerplate code must be written to access the Service. Thankfully, we can automate all that code generation. We will generate the bindings necessary for client side testing of the service using wsdl2java utility shipped with CXF. To do this:

    • Get hold of the wsdl document and place it under the "<project root>/src" folder. For the example, I retrieved the wsdl from from http://www.w3schools.com/webservices/tempconvert.asmx?wsdl and saved the file as - "<project root>/src/tempconvert.asmx.wsdl". Your development team can also provide you the same.  
    • Copy 2 files (cxf_wsdl2java.xml and cxf_wsdl2java.properties) from the attached project and place them under <project root>.
    • Open the file "cxf_wsdl2java.xml" and change the wsdl src reference under target "cxfWSDLToJava" to "src/tempconvert.asmx.wsdl"
    • Open cxf_wsdl2java.properties and change the first property "cxf_home" to home directory of CXF. (e.g cxf_home=/<directory>/apache-cxf-2.4.2)
    • Open the "Ant View" (Window -> Show View -> Ant) and drag and drop the "cxf_wsdl2java.xml" to the view and then run target "cxfWSDLToJava".
    • Once run, you should see the generated code under "src" folder within package "org.tempuri"

    If you look within the package contents classes, you will find an interface annotated with @WebService (org.tempuri.TempConvertSoap). This interface has 2 basic methods that represent the operations supported by the WebService. This is the remote interface we are going to use in our Test fixtures.

    Another class (org.tempuri.TempConvert) will be generated annotated with @WebServiceClient. This is the class that will return the remote interface. Methods annotated with @WebEndpoint will return you a remote interface. (in this case, we have used TempConvert.getTempConvertSoap() method)

    NOTE: If you would want to customize the JAX-WS implementations created by wsdl2java, it can be done by using a customization binding file. Please refer here for more information.


    3. Adding CXF Library references to your project

    • Go to "project properties->java build path->libraries tab"
    • Add "external jars" references to cxf-2.4.2.jar, neethi-3.0.1.jar, wsdl4j-1.6.2.jar, xmlbeans-2.4.0.jar, xmlschema-core-2.0.jar (all these are found under <cxf_home>/lib/ folder)

    4. Creating the remote interface instance

    • From the example project, copy the org.example.ConverterServiceFactory java file to your project, under package org.example
    • Open the scenarioContext-suite.xml file from your project and configure 2 beans like below (these will provide you the TempConvertSoap interface).

    <bean id="tempConvertorFactory" class="org.example.ConverterServiceFactory"
         init-method="start" destroy-method="stop" lazy-init="true">
         <property name="wsdlLocation" value="classpath:tempconvert.asmx.wsdl"/>
    </bean>
     
    <bean id="converterService" factory-bean="tempConvertorFactory" factory-method="getConverterServicePort"
          lazy-init="true" scope="singleton">
    </bean>


    5. Creating a scenario and generating test fixture

    • Assuming that you have a scenario "convert celsius.scn" (refer to the example project) which stated something like:


     Temperature Converter:

    •   verify that "100" degrees in centigrade is same as "212" degrees fahrenheit

     

    • Implement the step in fixture "Temperature Converter" (CMD+1 or right click ->quick fix) . This would have generated a fixture and a dummy implementation of the step. Navigate to the code for the step (right click -> show code). We need to hook up the service interface here.


    6. Injecting the service interface to the fixture

    • We can leverage Spring's annotation based configuration to inject the remote interface by simple declaring a private variable and annotating with @Autowired like below

    public class TemperatureConverter {
        
        @Autowired
        private TempConvertSoap converterService;
        ....
        
    }  

     

    7. Calling a remote service operation.

    • Navigate to the code for the step (right click -> show code). Now you are can use the remote interface like below:

    public void verifyThatDegreesInCentigradeIsSameAsDegreesFahrenheit(Double celsius, Double fahrenheit) throws Exception {
            assertEquals(fahrenheit, Double.valueOf(converterService.celsiusToFahrenheit(celsius.toString())));
     }


    8. Execute the scenario

    • You should see the scenario executing correctly.

     

    Additional support from Eclipse WTP

    - In addition, you can install "Eclipse WTP" plugins. This is a standard Indigo distro. If you would point to "http://download.eclipse.org/releases/indigo" update site, you can just install the "Web, XML, Java EE ... " feature. 
    - Once installed, you could then define your services preferences and generate the client side bindings using Apache Axis for example. (e.g. open "Apache Axis" at Project->Preferences->Web Services.)
    - You could then select the Twist project, click new -> Web Service Client, and in the following wizards, mention the wsdl def, and Axis would generate most of the java stub/code for you. Also it would add all the required dependencies onto your project. 
    - You could then write simple java code (from fixtures) to make service calls using the remote interface
     
  • angshuman
    Using a java bean to store/retrieve application values...
    Post posted December 12, 2011 by angshuman

    To seasoned Twisters this may be obvious, but here's one example how to use a simple java class as a bean to set/get values across scenarios.

    For example, say you are testing a web application and do some search, store values of search, and assert/do-something later on in another fixture/step.

     

    1. Create a Java class. For example, below is a simple class which has a key-value map, and provides simple apis for storing/retrieving values. In this example, the class is created in package "com.orgname.test" under the Twist test project's "src" directory.


    package com.orgname.test;

    import java.util.HashMap;
    import java.util.Map;

    public class AppDataPlaceHolder {

      private Map<String, Object> values = new HashMap<String, Object>();

      public void setValue(String key, Object value) {
          values.put(key, value);
      }

      public Object getValue(String key) {
          return values.get(key);
      }

    }



    2. Now define this class as a bean in "applicationContext-suite.xml" for your Twist test project. This will cause the bean to be instantiated when any test execution is requested for.



     <bean id="appData" class="com.orgname.test.AppDataPlaceHolder"/>




    3. In a test fixture, where you may want to store some application state across scenarios/steps, you may inject the above "ApplicationValues" object through the constructor. For example, if you have a fixture called "Search Amazon", then modify the constructor like below. Note, the example shows for a Twist Project with WebDriver as selected driver, but the pattern is same for any driver that you might have chosen.



    .....
    .....
    import com.orgname.test.AppDataPlaceHolder;

    public class SearchAmazon {
      ...
      private AppDataPlaceHolder appData;
     
      public SearchAmazon(WebDriver browser, AppDataPlaceHolder appData) {
            this.browser = browser;
            this.appData = appData;
        }
        .....

    }

     



    4. Now from any step implemented in the "Search Amazon" fixture you may store values onto the "AppDataPlaceHolder". For example, if you want to store the best-buy book for the author, you may do something as below

     


    public class SearchAmazon {
     .....
     ...
     private AppDataPlaceHolder appData;
     
     public SearchAmazon(WebDriver browser, AppDataPlaceHolder appData) {
            this.browser = browser;
            this.appData = appData;
        }
        .....

     public void searchForAuthor(String authorName) {
        //code to search for author
        appData.setValue(authorName, browser.findElement(By.className("best_buy")).getText());
     }

    }

     



    5. Now from another fixture you can access the previously stored values. (You just have to inject the "AppDataPlaceHolder" through the constructor like above):


    public void verifyAuthorBestBuy(String authorName, String bookName) {
       Object bestBuy = appData.getValue(authorName);
       .....
    }

     

  • johnstonv
    Table-Driven Scenario
    Post posted December 8, 2011 by johnstonv

     I've set up a table-driven scenario. At the end of my data-driven step, it loops back to the beginning of my first scenario context to start the next table row. How do I get it just to loop from the end of the scenario step to the beginning of the scenario step and not keep trying to log in again?

  • Matt Philip
    Files to ignore in source control
    Post posted December 8, 2011 by Matt Philip

    When using twist in source control, you can ignore/exclude the following files in the workspace:

    • WORKSPACE/.metadata files
    • WORKSPACE/PROJECT_NAME/bin (that contains the generated class files)
    • logs and reports folders (the reports folder appears only after you generate reports for the first time)
    • .metadata folder and any file that has the.log extension. 
  • Patrick
    Need help with Selenium user extensions for Twist Test6
    Post posted November 22, 2011 by Patrick

    We have been trying to get Twist to work with our SmartGWT user interfaces.  We were never able to get anything working with Sahi.

    Recently our search has led us to how SmartGWT initially suggests doing automated unit testing.  In the SmartGWT download there is a Selenium directory that provides a couple of extensions that can be used to lookup SmartGWT ids.  I can get this working with SeleniumIDE and I can record my tests from there.


    The problem is that I do not know how to add the file needed to be "seen" by the Selenium running in Twist.


    There are plenty of articles for how to do it in Selenium RC, but I don't know how to do it here.

     

    Here is an article for how this is done in RC:

    http://seleniumhq.org/docs/08_user_extensions.html

     

    We really like your product and the approach to testing, but we really need some help on this issue (being able to access SmartGWT ids) if we are going to be able to continue to use Twist.

    Recent Comment (3 of 6)

Recent Comments

Recent Participants

  • StJohn
  • Christopher Dalid
  • Lisa
  • Mark Richter
  • Steve Elkind
  • Ron
  • weswilliamz
  • jschwartz
  • Andy Yates
  • Suzie Prince
  • Arun Kumar
  • Ian Moes
  • plano2ktho
  • teresa gracias
  • Ladinar
  • Ethan Teng
  • John Downing
  • bitle
  • Scott Baldwin
  • Frank Oliver

Search this Forum

Keyword Search

Filter Posts with Tags