[eggPlant Functional] Keyword Driven Testing

In recent years, many software testers have chosen to adopt a “Keyword Driven” approach to test automation (sometimes also called “action words”, “test frameworks”, or “third-generation test automation”). In this approach, test cases are not defined directly in scripts, but in a simplified table format. Typically, each row in the table contains a keyword and associated parameters. So a table might look something like this:

	launch  	SuperApp
	verify  	SAMainScreen
	login   	joeuser  		 secretPassword
	verify  	loginSucceeded

Here, the keywords are launch, verify, login, and logout, but they could be any actions relevant to your testing context. The parameters are specific to each keyword, but might be image names or text to be typed and so forth.

One of the main reasons for adopting this approach is that it provides a fairly high-level, abstract representation of the steps to be taken to validate some functionality, without specifying the low-level details of how to carry out each of those actions. This makes it possible to specify a test before an application is fully functional and ready to be tested. The actual implementation of the scripts to carry out each keyword action can be developed later and can be changed over time to match changes in the application without having to change the test description in the table.

Some organizations also like this approach because it allows tests to be created by non-programmers, using a familiar tool such as a spreadsheet to create the table.

The suite presented here provides a foundation that shows one possible way to implement keyword driven testing in Eggplant. There is actually very little code involved. The KeywordDriver script provides the keywords and parameters, and calls the executeKeywords handler, which contains all of the interesting code.

The other scripts in the suite (launch.script, login.script, logout.script, and verify.script) are merely placeholders in this example that define the implementation of the keywords. To create your own keyword driven framework you would simply provide your own scripts to handle these or other keywords that are relevant in your test environment.

For those who like to look before they try, here is the complete executeKeywords handler:

to executeKeywords sourceText
	-- get the list of valid keywords and display it
	set validCommands to the short name of \
			each item of the files of my folder \
			where each ends with ".script" and each is not my name
	put validCommands, "- - -"
	-- process all of the source keywords and parameters
	repeat with each line sourceLine of sourceText
		put sourceLine split by comma into (command, paramList...)
		if command is not in validCommands then
			logError "Invalid Keyword: " & command
				-- run the command; pass paramList as individual params
				run command paramList as parameters
				logError "Error running " & command && paramList \
						& ": " & the exception
			end try
		end if
	end repeat
end executeKeywords

I don’t suppose you have any more examples of keyword driven testing using eggPlant do you? :mrgreen:

hi can u please give me code, on a product should install on different os(XP,Vista,Mac,Win7), please provide me script how to automate[/b]


I’m trying to set up a keyword driven framework and I’m stumbling a little at the first hurdle.

I’m just trying to run a .csv file called smokeTest.csv, which has a maximum of 5 delimited values in each row.

Am I correct in thinking that I don’t need to change the keywordDriver script and that I’d need another script that calls the handler with the CSV as a parameter of it?

Basically that’s what I’m trying to do without much luck at the moment! :oops:

We need a little more info on what problem you’re having. The approach you’ve outlined seems fine, but it seems like there’s a lot of room for interpretation in “without much luck at the moment.” Posting or sending your scripts would also help.

hi can u please give me code, on a product should install on different os(XP,Vista,Mac,Win7), please provide me script how to automate[/b]

@umamaheswarreddy.t: No one is going to be able to give you code to do this, since no one knows exactly what the steps are for the install, or whether the steps are the same on all platforms. In addition, you’ll need to capture your own images. The script itself is probably going to be mostly a series of Click commands.

Hi EggplantMatt,

I think the issue I’m having is that I don’t know how to feed the CSV file into the “executeKeywords” handler. At the moment I have a suite with the keyword Driver script in it (which I’ve renamed to executeKeywords) and I have another suite that has the keywords suite as a helper. In the suite without the driver I have a script called smokeTest that has the line

executeKeywords "smokeTest.csv"

I’ve tried different variants of this without much success. All that happens is I get a list of scripts that are in the keyword scripts folder and nothing else happens.

Do you need anymore info?

Think I cracked it. I’ve basically done the following:

put file "/keywordScripts/smokeTest.csv" into blabla
executeKeywords blabla

This now runs the script from the rows in the CSV file.

I’m going to fiddle about with it more now so it works sweetly with runwithnewresults to improve feedback.