common it() functions

I’m creating several BDD tests related to placing orders in the system. Each will be in their own cfc so they can be executed independently. The will share some common it() functions, for example, to log in as an admin.

`

it( “can login”, function(){
selenium.type(“name=loginName”, “johndoe”);
selenium.type(“name=password”, “password”);
selenium.click(“name=submit”);
selenium.waitForPageToLoad(“30000”);
expect( selenium.isTextPresent(“Welcome John”) );
expect( selenium.isTextPresent(“Log Out”) );
});

`

Where can I put this code such that it can be shared and called like sharedObj.login() from the test cfc’s?

Thanks,
Phil

Create a base class to inherit them from. Then call the method inside of a describe block.

Luis Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com
P/F: 1-888-557-8057

Perfect. Thanks!

-Phil

Can one of you put a quick example up? I’m trying to do this and keep getting an Array Error when I try to call them.

Here’s what our base class looks like

`
component extends=“cfselenium.BaseSpec”
{

public function loginToAdmin(){

it( “can open admin login page”, function(){
selenium.open("/apps/index.cfm?action=admin.login");
expect( selenium.isTextPresent( “User Name” ) );
});

it( “can login”, function(){
selenium.type(“name=loginName”, “john”);
selenium.type(“name=password”, “password”);
selenium.click(“name=submit”);
selenium.waitForPageToLoad(“30000”);
expect( selenium.isTextPresent(“John”) );
expect( selenium.isTextPresent(“Log Out”) );
});
}

}
`

Ah, gotcha. I was actually approaching the problem completely backwards. Thanks.

Dan

SO quick (hopefully) question.
I have three files
InterfaceTests - Written to test for a particular interface to which multiple files need to submit data
genericOfficeTests - One of the groups of files which need to submit to the interface
docTypeTests - Used to test the functionality for a specific file.

Each extends from the one above it and InterfaceTests extends from testbox.system.BaseSpec When all tests pass, no problem. When a test fails, I’m getting the error listed below.
question 1: Is this the correct / best way to set this up?
question 2: If not, what am I doing wrong and can I do something to fix that error?

Thanks

Interface Tests looks like this:

component extends="testbox.system.BaseSpec"{
  // Place your content here
    function interfaceTests(filename,thisFileResult){
        it("should be a struct",
            function()
            {
                    expect(thisFileResult).tobetypeof("struct");
            });
    }
}

genericOfficeTests (middle level) looks like this:

component  extends="tests.pdfCreation.pdfReneredFileInterface"{
  // Place your content here
    function officeTests(filename,testPDF,thisFileResult,result){

        it(title = "should return an array",
            data = {filename = filename, testPDF = testPDF, result = result, thisresult = thisFileResult},
            body =
                function(data)
                {
                        expect(data.result).tobetypeof("array");
                });
     }
}

and finally, docTypeTests looks like this:

component extends="tests.pdfCreation.genericOfficeTests"{

/*********************************** LIFE CYCLE Methods ***********************************/

   // executes before all suites+specs in the run() method
   function beforeAll(){

   }

   // executes after all suites+specs in the run() method
   function afterAll(){
   }

/*********************************** BDD SUITES ***********************************/

   function run(){
      thisFileResult={}
      describe("Office Tests",function(){
         officeTests("DummyData.txt",thisFileResult);
      });
      describe("Interface Tests",function(){
         interfaceTests("DummyData.txt",thisFileResult);
      });
   }
}

When all the tests pass, no problem. If one fails I get this error:

The element at position 1 cannot be found. |

  • |

The error occurred in C:/Users/djcar/Dropbox/sites/FalveySites/Yachts_Intranet/testbox/system/reports/assets/simple.cfm: line 194
Called from C:/Users/djcar/Dropbox/sites/FalveySites/Yachts_Intranet/testbox/system/reports/assets/simple.cfm: line 224
Called from C:/Users/djcar/Dropbox/sites/FalveySites/Yachts_Intranet/testbox/system/reports/assets/simple.cfm: line 142
Called from C:/Users/djcar/Dropbox/sites/FalveySites/Yachts_Intranet/testbox/system/reports/SimpleReporter.cfc: line 52
Called from C:/Users/djcar/Dropbox/sites/FalveySites/Yachts_Intranet/testbox/system/TestBox.cfc: line 308
Called from C:/Users/djcar/Dropbox/sites/FalveySites/Yachts_Intranet/testbox/system/TestBox.cfc: line 101
Called from C:/Users/djcar/Dropbox/sites/FalveySites/Yachts_Intranet/testbox/system/BaseSpec.cfc: line 517
|


<br>192 : - <strong>#htmlEditFormat( local.thisSpec.failMessage )#</strong><br>193 : <button onclick="toggleDebug( '#local.thisSpec.id#' )" title="Show more information">+</button><br><br>**194 : <div class="">#local.thisSpec.failOrigin[ 1 ].raw_trace#</div>**<br>195 : <cfif structKeyExists( local.thisSpec.failOrigin[ 1 ], "codePrintHTML" )><br>196 : <div class="">#local.thisSpec.failOrigin[ 1 ].codePrintHTML#</div> <br>

|

That section of simple.cfm looks like:

<button onclick="toggleDebug( '#local.thisSpec.id#' )" title="Show more information">+</button><br>

   <div class="">#local.thisSpec.failOrigin[ 1 ].raw_trace#</div>
      <cfif structKeyExists( local.thisSpec.failOrigin[ 1 ], "codePrintHTML" )>
   <div class="">#local.thisSpec.failOrigin[ 1 ].codePrintHTML#</div>
      </cfif>
<div class="box debugdata" data-specid="#local.thisSpec.id#">
   <cfdump var="#local.thisSpec.failorigin#" label="Failure Origin">
</div>

Is this the right place for that question?

Dan