[eggPlant Functional] Useful SenseTalk Functions

Thanks for all the great suggestions and comments from all our Eggplant users. Keep the questions coming!

This one comes from a large Bay Area company with dozens of Eggplant seats and is creating a fairly large testing and validation group around Eggplant.

Transitioning from, but still using a fairly manual test policy where testers run Eggplant scripts by hand, enter an email address at the start of the script so any validation information and reports can be sent to the proper engineers upon successful/failure of script/suite completion. The idea of email validation was needed, to at least ensure someone was entering a valid email and then use it for the SenseTalk SendMail command.

This AskForValidEmail was born as a result:

params aPrompt, aTitle, anAddress, useLast, allowCancel

-- Remember the last value entered ...
if useLast is not a boolean then set useLast to true
-- ... and allow cancel by default
if allowCancel is not a boolean then set allowCancel to true

repeat forever
  
  ask aPrompt title aTitle with anAddress
  
  -- get our results stored for later use.
  set ( theResult, email ) to ( the result, it )
  if email is empty and theResult is "Cancel" \
    and allowCancel then exit repeat
  
  if emailIsValid(email) then exit repeat
  if useLast then set anAddress to email
  
end repeat

return email

and this AskForValidEmail.script in turns calls a simple email validation EmailIsValid.script which checks basic email address validation rules.

params  address

if address is empty then return false

split address by "@"
if the number of items in address <> 2 then return false
set ( name, domain ) to ( items 1 to 2 of address )

-- ensure no inter-word spaces and one word for each
if number of words in name <> 1 then return false
if number of words in domain <> 1 then return false

-- and no outer-word spaces
if words 1 to -1 of name <> name then return false
if words 1 to -1 of domain <> domain then return false

return  true

You’ll see 5 parameters to the AskForValidEmail, however none are required. It is a good idea however to provide at least the first 2, the prompt and title of the ask window. The 3rd is an optional email address. The 4th parameter to the AskForValidEmail handler is the optional useLast, which by default if left out from the call, then defaults to true. This will allow the user to quickly make changes to their email address data. If you set it to false, then the user will be represented with the original calling email address in the ask panel. And finally, the optional 5th parameter is the allowCancel, which enables or disables the ability of the user to cancel out of the ask panel. By default, this is true.

Its not often we want a user ‘trapped’ in the use of an ask panel. However there are rare cases where this would be desirable and supported. Most likely, you will use this handler in the fashion shown.

Included is the EmailValidation.suite and its Demonstration.script demonstrating how simple these handlers work together. See how simple it is to do data validation with SenseTalk:

AskForValidEmail "Enter Email Address", \
  "Destination Email For Reports", \
  "errors@yourcompany.com"

set validEmailAddress to the result

put validEmailAddress