[OFBiz] Dev - My work on web auto test, based on TestMaker

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[OFBiz] Dev - My work on web auto test, based on TestMaker

Bugzilla from elliot.li@gmail.com
Hello,

I have been working on the automatic test of web applications.  My
work was based on TestMaker, and during these days I made lots of
improvement I thought necessary to TestMaker to make the writing of a
test script easier.  

Currently my work can be downloaded at

    http://www.mlogic.org/ofbiz/index.html

The package includes all the tools needed, my own library and a
sample.  You can read the README file on that page for detail
information.  I've been working on them to provide with more
information in near future.

For a brief introduction: TestMaker employes Jython as its script
language and now you can write easy-to-read test script like this:
(This is part from a sample script Party Test I wrote.)

    def runTest( self ):
        # This is the start point of this test case.
        self.login( )
        self.addTest( )
        self.findTest( )

    def login( self ):
        self.log( 0, "Start login." )

        # We go to the "logout" page, to clean cookies, then login
        # through filling the form on the "logout" page.

        self.get( self.urlBase + "logout" )

        # Extract form 1 from webpage ( form 0 is the locale setting
        # around the up right corner )

        myform = self.extractForm( 1 )

        # Fill it with username and password.

        self.fillForm( myform, "USERNAME", "admin" )
        self.fillForm( myform, "PASSWORD", "ofbiz" )

        # Post it.  As you can see, this procedure is very easy and clear.

        self.postForm( myform )

        self.log( 0, "Login success." )

    def goHome( self ):
        # This function go to the home page.
        self.get( self.urlBase + "findparty" )

    def findTest( self ):
        self.log( 0, "findTest start." )

        # We browse the party list to find if the party was correctly
        # added. We click the "Next" until the user name appear on
        # screen.

        # This line may be difficult to understand. We use get() to
        # display the first list page.  Since there are Javascript
        # codes in the findparty page, so it is difficult for us to
        # get to the list page by simulating the action of a normal
        # web browser, we have to get the url explicity.
        self.get( self.urlBase +
"findparty?showAll=Y&lookupFlag=Y&hideFields=Y" )

        # Dead loop until the name was found.
        while 1:
            try:

                # We use assertInResponse() to assert that a string is
                # in the response, or an exception would be thrown out.

                self.assertInResponse( self.userLastName + ', ' +
self.userFirstName )

                # If no exception, we would arrive here.
                self.log( 0, self.userLastName + ', ' +
self.userFirstName + " founded properly." )
                break

            except AssertionFailedError:
                self.log( 0, "Desired user not found in this screen,
go to next." )

                # clickURL() acts just like you clicking a hyperlink
                # in a webpage.

                self.clickURL( "Next" )

                # If the desired name can not be found in the list and
                # the last screen is reached, which has no "Next" any
                # more, then the clickURL() would throw an exception
                # indicating that the desired hyperlink could not be
                # found, thus this test will fail.

        self.log( 0, "findTest passed." )

    def addTest( self ):
        self.log( 0, "addTest start," )
        self.goHome()

        #Use TestMaker's Lingo to generate a fake user name
        self.userFirstName = self.lingo.getMessage( 1, 1, 1, 0 )
        self.userLastName = self.lingo.getMessage( 1, 1, 1, 0 )
        self.log( 0, "Create a new user: " + self.userFirstName + " "
+ self.userLastName )

        self.clickURL( "Create" )
        self.clickURL( "[*] Create New Person" )

        # Extract the form, fill it, then post it.
        form = self.extractForm( 1 )
        self.fillForm( form, "firstName", self.userFirstName )
        self.fillForm( form, "lastName", self.userLastName )
        self.postForm( form )

        # During all web related action, error check would be done
        # automatically to assert there are no "Error" or "Exception"
        # text in the response.

        self.log( 0, "addTest passed." )

And the running screen of this test script would like this:

    test: Initialize
    test: setUp
    Start login.
    Request step: 1, http://localhost:8080/partymgr/control/logout
    Extract form from response.
    Post form.
    Request step: 2,
http://localhost:8080/partymgr/control/login;jsessionid=2F40263C75BC12869459B4D27F7FCB88.jvm1
    Login success.
    addTest start,
    Request step: 3, http://localhost:8080/partymgr/control/findparty
    Create a new user: Aquam Via
    Click URL: Create
    Request step: 4, http://localhost:8080/partymgr/control/createnew
    Click URL: [*] Create New Person
    Request step: 5,
http://localhost:8080/partymgr/control/editperson?create_new=Y
    Extract form from response.
    Post form.
    Request step: 6, http://localhost:8080/partymgr/control/createPerson
    addTest passed.
    findTest start.
    Request step: 7,
http://localhost:8080/partymgr/control/findparty?showAll=Y&lookupFlag=Y&hideFields=Y
    Desired user not found in this screen, go to next.
    Click URL: Next
    Request step: 8,
http://localhost:8080/partymgr/control/findparty?VIEW_SIZE=20&VIEW_INDEX=2&hideFields=Y&lookupFlag=Y&showAll=Y&extInfo=null
    Desired user not found in this screen, go to next.
    Click URL: Next
    Request step: 9,
http://localhost:8080/partymgr/control/findparty?VIEW_SIZE=20&VIEW_INDEX=3&hideFields=Y&lookupFlag=Y&showAll=Y&extInfo=null
    Desired user not found in this screen, go to next.
    Click URL: Next
    Request step: 10,
http://localhost:8080/partymgr/control/findparty?VIEW_SIZE=20&VIEW_INDEX=4&hideFields=Y&lookupFlag=Y&showAll=Y&extInfo=null
    Via, Aquam founded properly.
    findTest passed.
    test: tearDown
    All test passed.

For more information, please refer to the README in the package.

--
Best regards,
Yan
 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev