public static class SAFSPlus.DriverCommand
extends java.lang.Object
Constructor and Description |
---|
DriverCommand() |
Modifier and Type | Method and Description |
---|---|
static boolean |
AssignClipboardVariable(java.lang.String varName)
Copy the clipboard contents to a DDVariable.
|
static boolean |
CallJUnit(java.lang.String clazzes)
Invoke one or more JUnit tests using the provided Class name(s).
|
static boolean |
CallRemote(java.lang.String protocol,
java.lang.String system,
java.lang.String service,
java.lang.String command,
java.lang.String resultVar,
java.lang.String... params)
Execute a command on an external/local system or application.
|
static boolean |
CallScript(java.lang.String path)
Execute an external selenium script in the currently running WebDriver.
The external selenium script is recorded by a testing tool, such as "Selenium Builder" or "Selenium IDE". |
static java.awt.geom.Point2D.Double |
CaptureMousePositionOnScreen(java.lang.String variableX,
java.lang.String variableY)
Capture the location of the mouse pointer relative to the screen and save the x and y components into variables.
|
static boolean |
ClearAllVariables()
Clear storage of all DDVariables.
|
static boolean |
ClearAppMapCache()
Clear the internal application map cache.
|
static boolean |
ClearArrayVariables(java.lang.String prefix)
Clear storage of all SAFS variables containing a specific prefix.
|
static boolean |
ClearClipboard()
Clear the contents of the Window's clipboard.
|
static boolean |
CloseApplication(java.lang.String ApplicationID)
Close a named application process launched with LaunchApplication.
|
static boolean |
CloseApplicationMap(java.lang.String mapID)
By map ID, Close a opened Application Map in App Map chain.
|
static boolean |
CopyVariableValueEx(java.lang.String sourceVar,
java.lang.String destVar)
Copy the value of a (dynamic) DDVariable to another.
|
static boolean |
Delay(int milliseconds)
Pause test-case flow in milliseconds.
|
static boolean |
Expressions(boolean on)
Enable and Disable enhanced expressions.
|
static java.lang.String |
GetRegistryKeyValue(java.lang.String key,
java.lang.String keyValue)
Get the value of the specified Registry Key to a variable.
|
static boolean |
GetRegistryKeyValue(java.lang.String key,
java.lang.String keyValue,
java.lang.String result)
Assign the value of the specified Registry Key to a variable.
|
static java.lang.String |
GetSystemDate()
Get the string value of the system date in the format MM-DD-YYYY
|
static java.lang.String |
GetSystemDateTime(boolean military)
Get the string value of the system date-time in the format MM-DD-YYYY HH:MM:SS
|
static java.lang.String |
GetSystemTime(boolean military)
Get the string value of the system time in the format HH:MM:SS
|
static boolean |
GetURL(java.lang.String url,
java.lang.String variable,
java.lang.String... optionals)
Send a "GET" HTTP Request by AJAX, and save the response to a variable.
|
static boolean |
Highlight(boolean OnOff)
Highlight object
|
static boolean |
LaunchApplication(java.lang.String ApplicationID,
java.lang.String ExecutablePath,
java.lang.String... params)
Identify and Launch a specified application
|
static java.lang.String |
OnGUIExistsGotoBlockID(Component component,
java.lang.String blockid,
java.lang.String... optionals)
Goto the named block in the current table if a GUI component exists.
|
static java.lang.String |
OnGUINotExistGotoBlockID(Component component,
java.lang.String blockid,
java.lang.String... optionals)
Goto the named block in the current table if a GUI component does not exist.
|
static boolean |
Pause(int seconds)
Pause test-case flow in seconds.
|
static boolean |
SaveClipboardToFile(java.lang.String file,
java.lang.String... optionals)
Save the clipboard contents to a text file.
|
static boolean |
SaveURLToFile(java.lang.String url,
java.lang.String file,
java.lang.String... optionals)
Send a "GET" HTTP Request by AJAX, and save the response to a file.
|
static boolean |
ScrollWheel(int wheelAmount)
Move mouse wheel forward or backward.
|
static boolean |
SendMail(java.lang.String from,
java.lang.String to,
java.lang.String subject,
java.lang.String message,
java.lang.String... attachment)
Send email via a mail server, which should be configured by user in the .INI file.
This method will not verify the validation of the recipients address. |
static boolean |
SetApplicationMap(java.lang.String mapID)
Load/Set/Change an Application Map and put it on top of App Map chain.
No action or command relying on the contents of a particular Application Map will work properly if the Map has not been previously loaded by this command or similar test initialization processes-- like an AppMap.order initialization file. |
static boolean |
SetClipboard(java.lang.String content)
Set a string content to the clipboard.
|
(package private) static boolean |
SetContext(Component component)
Give a Window or Component input focus.
|
(package private) static boolean |
SetFocus(Component component)
Give a Window or Component input focus.
|
static boolean |
SetImageDebug(boolean on)
Enable/Disable verbose debug log during using IBT.
Normally, it is off. |
static boolean |
SetImageFuzzyMatching(boolean on)
|
static boolean |
SetMillisBetweenRecords(int milliseconds)
Set the general pause time between records (SAFSPlus API calls), in milliseconds.
|
static boolean |
SetMultipleThreadSearch(boolean on)
|
static boolean |
SetVariableValueEx(java.lang.String variable,
java.lang.String value)
Set the value of a variable/DDVariable; for DDVariable, refer to
SAFSPlus Note3.The different between this method and SAFSPlus#SetVariableValue(String, String) is that this method can take a variable or DDVariable as the first parameter, the later one can only take variable. |
static boolean |
SetVariableValues(java.lang.String varEqualVal,
java.lang.String... optionals)
Set the value of one or more DDVariables; for DDVariable, refer to
SAFSPlus Note3. |
static boolean |
StartWebBrowser(java.lang.String URL,
java.lang.String BrowserID,
java.lang.String... params)
Start WebBrowser
See Detailed Reference
|
static boolean |
StopWebBrowser(java.lang.String BrowserID)
Stop WebBrowser by ID.
|
static boolean |
TakeScreenShot(java.lang.String testFile)
Take screenshot and save it to a test file.
|
static boolean |
TakeScreenShot(java.lang.String testFile,
ImageUtils.SubArea subarea)
Take screenshot and save it to a test file.
|
static boolean |
UseWebBrowser(java.lang.String ID)
Switch WebBrowser by ID.
|
static boolean |
VerifyClipboardToFile(java.lang.String benchFile,
java.lang.String... optionals)
Verify the current contents of the Windows clipboard with a benchmark file.
|
static boolean |
VerifyURLContent(java.lang.String url,
java.lang.String content,
java.lang.String... optionals)
Send a "GET" HTTP Request by AJAX, and Verify URL Content with a string content.
|
static boolean |
VerifyURLToFile(java.lang.String url,
java.lang.String file,
java.lang.String... optionals)
Send a "GET" HTTP Request by AJAX, and Verify URL Content with a file.
|
static boolean |
WaitForGUI(Component comp,
long time)
Wait for object in seconds
|
static boolean |
WaitForGUI(Component component,
java.lang.String... optionals)
Wait for a Window or Component to become valid.
|
static boolean |
WaitForGUIGone(Component component,
java.lang.String... optionals)
Wait for a Window or Component to become invalid.
|
static boolean |
WaitForPropertyValue(Component component,
java.lang.String propertyName,
java.lang.String expectedValue,
java.lang.String... optionals)
Wait for a specific Window or Component property value to match an expected value.
|
static boolean |
WaitForPropertyValueGone(Component component,
java.lang.String propertyName,
java.lang.String expectedValue,
java.lang.String... optionals)
Wait for a specific Window or Component property value to change from a known value.
|
static boolean |
WaitForRegistryKeyExists(java.lang.String key,
java.lang.String... optionals)
Wait for a Registry Key to become valid.
|
static boolean |
WaitForRegistryKeyValue(java.lang.String key,
java.lang.String value,
java.lang.String expectedValue,
java.lang.String... optionals)
Wait for a specific Registry KeyValue to match an expected value.
|
public static boolean AssignClipboardVariable(java.lang.String varName)
varName
- The name of the DDvariable variable to hold the clipboard text.SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
boolean success = Misc.AssignClipboardVariable(VAR_CLIPBOARD);
String contents = GetVariableValue(VAR_CLIPBOARD);
public static boolean CallJUnit(java.lang.String clazzes)
clazzes
- String, the JUnit class names separated by semi-colon, colon, comma, or space.TestRecordData.getStatusInfo()
to get it.SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
TestRecordData.getStatusInfo()
//Execute a JUnit Test "com.sas.spock.tests.SpockExperiment"
boolean success = Misc.CallJUnit("com.sas.spock.tests.SpockExperiment");
//Execute 2 JUnit Tests "com.sas.spock.tests.SpockExperiment and myapp.tests.AnOtherTest"
boolean success = Misc.CallJUnit("com.sas.spock.tests.SpockExperiment;myapp.tests.AnOtherTest");
//JUnitTestClasses is centrally stored in the App Map as "com.sas.spock.tests.SpockExperiment;myapp.tests.AnOtherTest"
boolean success = Misc.CallScript(Map.JUnitTestClasses());
public static boolean CallScript(java.lang.String path)
path
- -- full absolute path or project-relative path to an existing script to execute.SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
//Run a JSON script stored centrally in the App Map.
//-- Map File --------------
//[ApplicationConstants]
//CheckBoxJSONScript=C:\Automation\SharedStorage\Selenium\checkbox.json
//---------------------------
boolean success = Misc.CallScript(Map.CheckBoxJSONScript());
//Literal String examples (not recommended):
//Run a JSON script (checkbox.json), which is in a Scripts sub-directory for the Project.
boolean success = Misc.CallScript("Scripts\checkbox.json");
//Run a JSON script (checkbox.json), which is provided using a full absolute path.
boolean success = Misc.CallScript("C:\Automation\SharedStorage\Selenium\checkbox.json");
//Run an HTML script (checkbox.html), which is in Scripts sub-directory for the Project.
boolean success = Misc.CallScript("Scripts\checkbox.html");
public static boolean CallRemote(java.lang.String protocol, java.lang.String system, java.lang.String service, java.lang.String command, java.lang.String resultVar, java.lang.String... params)
protocol
- -- only "STAF" currently supported. Defaults to "STAF" if null.system
- -- the external/local system name or id to send the command to.service
- -- the service or process on the system targetted.command
- -- the command to be issued to the the service or process.resultVar
- -- the DDVariable name to receive the results of the call.params
- -- additional parameters (String or String[]), if any, to be passed with the command.
SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
boolean success = Misc.CallRemote("STAF", "local", "service", "list", STAF_RESULT);
String resultStr = GetVariableValue(STAF_RESULT);
public static boolean Expressions(boolean on)
on
- boolean, true to enable the enhanced expressions; false to disable.SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
Misc.Expressions(true);
Logging.LogMessage("Expression On", "58+45");//Log result is 103
Misc.Expressions(false);//the evaluation of expression will be off until Expressions(true) is called.
Logging.LogMessage("Expression Off", "58+45");//Log result is '58+45'
,
Misc.Expressions(true);
Logging.LogMessage("assign a variable var", "^var=58+45");//only when first letter is ^, the string between ^ and = will be consider as variable name
String value = SAFSPlus.GetVariableValue("var");
Logging.LogMessage("get value for variable var", value);
Logging.LogMessage("the value of variable var is", "^var");//only when first letter is ^, the string between ^ and = will be consider as variable name
,
Component combobox = new Component(new Component("Window"), "ComboBox");
Misc.Expressions(true);
ComboBox.CaptureItemsToFile(combobox, URL+"ComboBoxData.txt", "UTF-8");//Fail to store as UTF8 file, "UTF-8" is processed as an arithmetic expression
Misc.Expressions(false);
ComboBox.CaptureItemsToFile(combobox, "ComboBoxData.txt", "UTF-8");//Save as UTF8 file
public static java.awt.geom.Point2D.Double CaptureMousePositionOnScreen(java.lang.String variableX, java.lang.String variableY) throws SeleniumPlusException
variableX
- String, The name of the DDVariable to store the X component of the mouse position.variableY
- String, The name of the DDVariable to store the Y component of the mouse position.SeleniumPlusException
SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
Point2D.Double mousePosition = Misc.CaptureMousePositionOnScreen("positionX", "positionY");
Logging.LogMessage("Mouse position: ", "["+mousePosition.x+","+mousePosition.y+"]");
public static boolean ClearAllVariables()
SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
public static boolean ClearAppMapCache()
SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
public static boolean ClearArrayVariables(java.lang.String prefix)
prefix
- String, The variable name prefix to use for the delete.SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
boolean success = Misc.ClearArrayVariables("TCAFS.UID.");//All variables beginning with "TCAFS.UID." will be deleted.
public static boolean ClearClipboard()
SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
public static boolean CloseApplication(java.lang.String ApplicationID)
ApplicationID
- String, A text ID to reference the application to close.SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
boolean success = Misc.CloseApplication("NotePad");
public static boolean CloseApplicationMap(java.lang.String mapID) throws SeleniumPlusException
mapID
- String, the ID of the map to be closed. The ID is usually the map file name.SetApplicationMap(String)
.SeleniumPlusException
SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
Misc.CloseApplicationMap("App.map");
public static boolean CopyVariableValueEx(java.lang.String sourceVar, java.lang.String destVar)
sourceVar
- String, The name of the variable to copy.destVar
- String, The name of the variable to receive the copy.SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
String var = "myvar";
String dest = "mydest";
String value = "myvar_value";
if(SetVariableValue(var, value) && Misc.CopyVariableValueEx(var, dest))
if(!GetVariableValue(dest).equals(value)) System.err.println("Error copy value.");
public static boolean Delay(int milliseconds)
Pause(int)
.milliseconds
- int, the milliseconds to pausePause(int)
public static boolean LaunchApplication(java.lang.String ApplicationID, java.lang.String ExecutablePath, java.lang.String... params)
ApplicationID
- String, A text ID to reference the applicationExecutablePath
- String, The path, filename, and parameters for the executable OR an ApplicationConstant.params
- -- SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
boolean success = Misc.LaunchApplication("NotePad", "notepad.exe c:\\sample.txt");
public static boolean GetRegistryKeyValue(java.lang.String key, java.lang.String keyValue, java.lang.String result)
key
- String, The registry Key to seekkeyValue
- String, The value name under the parent key to seekresult
- String, The name of the variable to receive the value of the registry key.SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
String key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment";
String keyValue = "CurrentVersion";
String result = "result";
if(Misc.GetRegistryKeyValue(key, keyValue, result))
System.out.println(key+":"+keyValue+" = "+GetVariableValue(result));
public static boolean GetURL(java.lang.String url, java.lang.String variable, java.lang.String... optionals)
url
- String, The URL to request.variable
- String, The name of the variable holding the content of responseoptionals
- SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
String url = "http://rest.api.url";
String variable = "response";
//Get content of url and wait for response with timeout 60 seconds, save result to variable.
if(Misc.GetURL(url, variable, "60")){
System.out.println("content of url '"+url+"' has been saved to variable '"+variable+"'.");
System.out.println("content: \n"+GetVariableValue(variable));
System.out.println("ready state: "+GetVariableValue(variable+".readyState"));
System.out.println("status code: "+GetVariableValue(variable+".status"));
System.out.println("status text: "+GetVariableValue(variable+".statusText"));
System.out.println("response headers: \n"+GetVariableValue(variable+".headers"));
System.out.println("XML content: "+GetVariableValue(variable+".xml"));
}
//Get content of url with headers ("Accept", "text/*") and ("Accept-Charset", "UTF-8")
//and wait for response with timeout 60 seconds, save result to variable.
if(Misc.GetURL(url, variable, "60", "Accept", "text/*", "Accept-Charset", "UTF-8" )){
System.out.println("content of url '"+url+"' has been saved to variable '"+variable+"'.");
}
public static java.lang.String GetRegistryKeyValue(java.lang.String key, java.lang.String keyValue)
key
- String, The registry Key to seekkeyValue
- String, The value name under the parent key to seekSAFSPlus.prevResults
,
String key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment";
String keyValue = "CurrentVersion";
String result = Misc.GetRegistryKeyValue(key, keyValue);
public static java.lang.String GetSystemDate()
SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
System.out.println("SystemDate "+Misc.GetSystemDate());
public static java.lang.String GetSystemDateTime(boolean military)
military
- boolean, if true the hour string will be 24-hours format; otherwise is 12 AM/PM.SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
System.out.println("SystemDateTime "+Misc.GetSystemDateTime(true));
System.out.println("SystemDateTime "+Misc.GetSystemDateTime(false));
public static java.lang.String GetSystemTime(boolean military)
military
- boolean, if true the hour string will be 24-hours format; otherwise is 12 AM/PM.SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
System.out.println("SystemTime "+Misc.GetSystemTime(true));
System.out.println("SystemTime "+Misc.GetSystemTime(false));
public static boolean Highlight(boolean OnOff)
OnOff
- -- true or false for object highlightpublic static boolean Pause(int seconds)
Delay(int)
.seconds
- int, the seconds to pauseSAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
TestRecordData.getStatusInfo()
,
Delay(int)
Pause(20);
public static boolean SetMillisBetweenRecords(int milliseconds)
milliseconds
- int, pause time between records, in milliseconds.public static boolean StartWebBrowser(java.lang.String URL, java.lang.String BrowserID, java.lang.String... params)
URL
- String,BrowserID
- String, Unique application/browser ID.params
- optional, currently ONLY supported for Selenium WebDriver Engine.
BrowserConstants#DEFAULT_BROWSER
), it can be one of:
Constants.BrowserConstants.BROWSER_NAME_CHROME
Constants.BrowserConstants.BROWSER_NAME_FIREFOX
Constants.BrowserConstants.BROWSER_NAME_IE
params[1] timeout int, in seconds. Implicit timeout for search elements
params[2] isRemote boolean, (no longer used -- everything is now "remote")
Following parameters indicate the extra parameters, they MUST be given by PAIR(key, value)
The key can be one of:
params[3] extra parameter key1
params[4] extra parameter value for key1
params[5] extra parameter key2
params[6] extra parameter value for key2
params[7] extra parameter key3
params[8] extra parameter value for key3
...
SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
TestRecordData.getStatusInfo()
,
StopWebBrowser(String)
,
#SwitchWebBrowser(String)
StartWebBrowser("http://www.google.com", "GoogleMain"); StartWebBrowser("http://www.google.com", "GoogleMain", BrowserConstans.BROWSER_NAME_CHROME); StartWebBrowser("http://www.google.com", "GoogleMain", BrowserConstans.BROWSER_NAME_IE, "10"); The following gives some examples to start web browser with "custom profile" and "preferences". For the detail explanation of starting browser with "custom profile" and/or "preferences", please visit the section "Start Browser" at Selenium Welcome Document. //Start firefox browser with custom profile "myprofile" ( Create custom profile) StartWebBrowser("http://www.google.com", "GoogleMain", new String[]{ BrowserConstans.BROWSER_NAME_FIREFOX, "10", "true", BrowserConstans.KEY_FIREFOX_PROFILE, "myprofile" }); //Start firefox browser with some preference to set. String absolutePreferenceFile = "c:\\firefoxPref.json.dat";//A json file containing chrome preferences, like { "intl.accept_languages":"zh-cn", "accessibility.accesskeycausesactivation":false, "browser.download.folderList":2 } StartWebBrowser("http://www.google.com", "GoogleMain", new String[]{ BrowserConstans.BROWSER_NAME_FIREFOX, "10", "true", quote(BrowserConstans.KEY_FIREFOX_PROFILE_PREFERENCE), quote(absolutePreferenceFile) }); //Start chrome browser with default data pool (chrome://version/, see "Profile Path") , and using the last-used user. String datapool = "C:\\Users\\some-user\\AppData\\Local\\Google\\Chrome\\User Data"; StartWebBrowser("http://www.google.com", "GoogleMain", new String[]{ BrowserConstans.BROWSER_NAME_CHROME, "10", "true", quote(BrowserConstans.KEY_CHROME_USER_DATA_DIR), datapool }); //Start chrome browser with default data pool (chrome://version/, see "Profile Path") , and using the default user. String datapool = "C:\\Users\\some-user\\AppData\\Local\\Google\\Chrome\\User Data"; StartWebBrowser("http://www.google.com", "GoogleMain", new String[]{ BrowserConstans.BROWSER_NAME_CHROME, "10", "true", quote(BrowserConstans.KEY_CHROME_USER_DATA_DIR), datapool, quote(BrowserConstans.KEY_CHROME_PROFILE_DIR), "Default" }); //Start chrome browser with custom data, and using the last-used user. StartWebBrowser("http://www.google.com", "GoogleMain", new String[]{ BrowserConstans.BROWSER_NAME_CHROME, "10", "true", quote(BrowserConstans.KEY_CHROME_USER_DATA_DIR), "c:\\chrome_custom_data"//Create custom data pool }); //Start chrome browser with custom data, and using the 1th user. StartWebBrowser("http://www.google.com", "GoogleMain", new String[]{ BrowserConstans.BROWSER_NAME_CHROME, "10", "true", quote(BrowserConstans.KEY_CHROME_USER_DATA_DIR), "c:\\chrome_custom_data",//Create custom data pool quote(BrowserConstans.KEY_CHROME_PROFILE_DIR), "Profile 1" }); //Start chrome browser with some options to be turned off. String optionsToExclude = "disable-component-update";//comma separated options to exclude, like "disable-component-update, ignore-certificate-errors", be careful, there are NO 2 hyphens before options. StartWebBrowser("http://www.google.com", "GoogleMain", new String[]{ BrowserConstans.BROWSER_NAME_CHROME, "10", "true", quote(BrowserConstans.KEY_CHROME_EXCLUDE_OPTIONS), quote(optionsToExclude) }); //Start chrome browser with some chrome-command-line-options/preferences to set. String absolutePreferenceFile = "c:\\chromePref.json.dat";//A json file containing chrome command-line-options/preferences, like { "lang":"zh-cn", "start-maximized":"", "seplus.chrome.preference.json.key":{ "intl.accept_languages":"zh-CN-pseudo", "intl.charset_default" :"utf-8"} } StartWebBrowser("http://www.google.com", "GoogleMain", new String[]{ BrowserConstans.BROWSER_NAME_CHROME, "10", "true", quote(BrowserConstans.KEY_CHROME_PREFERENCE), quote(absolutePreferenceFile) });
public static boolean StopWebBrowser(java.lang.String BrowserID)
#StartWebBrowser(String, BrowserID, String...)
#StartWebBrowser(String, BrowserID, String...)
BrowserID
- String, the BrowserID served as key to get the WebDriver from cache.Sets prevResults TestRecordHelper to the results received or null if an error occurred.
SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
TestRecordData.getStatusInfo()
,
StartWebBrowser(String, String, String...)
String browserID = "GoogleMain";
StartWebBrowser("http://www.google.com", browserID);
//do some testing, then
StopWebBrowser(browserID);
public static boolean SendMail(java.lang.String from, java.lang.String to, java.lang.String subject, java.lang.String message, java.lang.String... attachment)
from
- - Sender's email address.to
- - Receiver's email. Multiple receivers allowed by semicolon(";");subject
- - Subject line of the email.message
- - Email message, html default format.optionals
- - Attachment file. Multiple files allowed by semicolon(";").
Prerequisite:
in test.ini setup following
[SAFS_DRIVERCOMMANDS]
OUT_MAILSERVER="mail server"
OUT_MAILSERVERPORT=25|465|587
OUT_MAILSERVERPROTOCOL=SMTP|SMTPS|TLS
OUT_MAILUSER=user.name@mail.com
OUT_MAILPASS=*******
[SAFS_DRIVER]
SMTP="mail server" (deprecated, replaced by OUT_MAILSERVER)
PORT=25 (deprecated, replaced by OUT_MAILSERVERPORT)
Misc.SendMail("Sender@email.com", "Recipient1@email.com;@Recipient2@email.com", "Subject line", "Email message",
"Attachment 1 filename; Attachment 2 filename");
CountStatusInterface info = Counters.GetCounterStatus("TestCase1") or Counters.StartCounter("test1")
String message = "Total Records: " + info.getTotalRecords() + "\nTotal Pass: " +
info.getTestPasses() +"\nTotal Fail: " + info.getTestFailures();
Misc.SendMail("sender@email.com","to1@email.com", "Test results", message,"Logs\\TestCase1.txt");
public static boolean SaveURLToFile(java.lang.String url, java.lang.String file, java.lang.String... optionals)
url
- String, The URL to request.file
- String, The file to save the response from the server.
This can be a full path, a relative path, or a file name.
For relative path, it is appended to the project's path to build the full path of the file.
For file name, the file is saved under the project's test directory (it is Datapool\Test in SAFS or Actuals in SE+).
In any case the parent folder of the file must exist. optionals
- SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
String url = "http://rest.api.url";
String file = "response.html";
//Get content of url and wait for response with default timeout 120 seconds, save result to file.
if(Misc.SaveURLToFile(url, file)){
System.out.println("content of url '"+url+"' has been saved to file '"+file+"'.");
}
//Get content of url with headers ("Accept", "text/*") and ("Accept-Charset", "UTF-8")
//and wait for response with timeout 60 seconds, save result to file.
if(Misc.SaveURLToFile(url, variable, "60", "Accept", "text/*", "Accept-Charset", "UTF-8" )){
System.out.println("content of url '"+url+"' has been saved to file '"+file+"'.");
}
public static boolean SetApplicationMap(java.lang.String mapID) throws SeleniumPlusException
mapID
- String, the ID of the map to open.SeleniumPlusException
SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
Misc.SetApplicationMap("App.map");
Misc.SetApplicationMap("d:\\mytest\\App.map");
public static boolean SaveClipboardToFile(java.lang.String file, java.lang.String... optionals)
file
- String, The file name to store the clipboard's content
Absolute file path. Relative file path, if it contains file separator, it is relative to datapool or project root. otherwise it is relative to the project test folder.
optionals
- --SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
Misc.SaveClipboardToFile(D:\test\clipboard.txt);
Misc.SaveClipboardToFile(clipboard.txt);//Save to file under project test folder
public static boolean ScrollWheel(int wheelAmount)
wheelAmount
- int, The amount of wheel to scrollSAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
Misc.ScrollWheel(25);
Misc.ScrollWheel(-15);
public static boolean SetClipboard(java.lang.String content)
content
- String, The content to set to clipboard.SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
String clipboardValue = "THIS IS SOMETHING TO BE SET TO CLIPBOARD!";
Misc.SetClipboard(clipboardValue);
static boolean SetContext(Component component) throws SeleniumPlusException
component
- org.safs.model.Component, The component to gain focus.SeleniumPlusException
SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
Misc.SetContext(Map.SAPDemoPage.SAPDemoPage);
Misc.SetContext(Map.SAPDemoPage.Basc_Password);
static boolean SetFocus(Component component) throws SeleniumPlusException
component
- org.safs.model.Component, The component to gain focus.SeleniumPlusException
SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
Misc.SetFocus(Map.SAPDemoPage.SAPDemoPage);
Misc.SetFocus(Map.SAPDemoPage.Basc_TextArea);
public static boolean SetImageDebug(boolean on)
on
- boolean, true to turn on; false to turn off.SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
Misc.SetImageDebug(true);
public static boolean SetImageFuzzyMatching(boolean on)
on
- boolean, true to turn on; false to turn off.SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
Misc.SetImageFuzzyMatching(true);
public static boolean SetMultipleThreadSearch(boolean on)
on
- boolean, true to turn on; false to turn off.SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
Misc.SetMultipleThreadSearch(true);
public static boolean SetVariableValueEx(java.lang.String variable, java.lang.String value)
SAFSPlus
Note3.variable
- String, The name of variable or DDVariable that evaluates to a valid variable name.value
- String, The content to set to variable.SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
TestRecordData.getStatusInfo()
,
Misc.Expressions(true);
String user_name_var = "user.name";//variable
String user_name = "NewUserName";//value
//Create a reference "ref_user_name_var" to variable "user.name"
String refToUsernameVar = "ref_user_name_var";//reference to variable "user.name"
Misc.SetVariableValueEx(refToUsernameVar, user_name_var);
//Use the reference to set value to variable "user.name"
Misc.SetVariableValueEx("^"+refToUsernameVar, user_name);
if(!username.equals(GetVariableValue(user_name_var))) System.err.println("Fail SetVariableValues");
public static boolean SetVariableValues(java.lang.String varEqualVal, java.lang.String... optionals)
SAFSPlus
Note3.varEqualVal
- String, The DDVariable along with its value.optionals
- SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
TestRecordData.getStatusInfo()
,
Misc.Expressions(true);
//set value "UserA" to variable "user.name", set "Password1" to "user.password"
Misc.SetVariableValues("^user.name=UserA","^user.password=Password1");
//input the value of variable "user.name"
Component.InputCharacters(Map.AUT.UserInput, "^user.name");
//input the value of variable "user.password"
Component.InputCharacters(Map.AUT.PassWord, "^user.password");
public static boolean TakeScreenShot(java.lang.String testFile, ImageUtils.SubArea subarea)
testFile
- String, The test file name to save the screenshot.
Absolute file path. Relative file path, if it contains file separator, it is relative to datapool or project root. otherwise it is relative to the project test folder.
subarea
- SubArea, indicating partial image of the screen to captureSAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
//Take a whole screen image
Misc.TakeScreenShot("D:\test\screenshot.png");
//Take a sub image of screen
SubArea subarea = new SubArea(0,0,"20%","30%");
Misc.TakeScreenShot("sub_screenshot.png", subarea);
public static boolean TakeScreenShot(java.lang.String testFile)
testFile
- String, The test file name to save the screenshot.
Absolute file path. Relative file path, if it contains file separator, it is relative to datapool or project root. otherwise it is relative to the project test folder.
SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
Misc.TakeScreenShot("D:\test\screenshot.png");
Misc.TakeScreenShot("screenshot.png");//Save to project test folder
public static boolean UseWebBrowser(java.lang.String ID)
#StartWebBrowser(String, int, String...)
#StartWebBrowser(String, int, String...)
ID
- String, the ID served as key to get the WebDriver from cache.SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
TestRecordData.getStatusInfo()
,
StartWebBrowser(String, String, String...)
UseWebBrowser("GoogleNewWindow");
public static boolean VerifyClipboardToFile(java.lang.String benchFile, java.lang.String... optionals)
benchFile
- String, The bench file name to compare with the clipboard's content.Absolute file path. Relative file path, if it contains file separator, it is relative to datapool or project root. otherwise it is relative to the project bench folder.
optionals
- SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
Misc.VerifyClipboardToFile("D:\bench\clipboard.txt");
Misc.VerifyClipboardToFile("clipboard.txt");//Compare with the file under project bench directory
public static boolean VerifyURLContent(java.lang.String url, java.lang.String content, java.lang.String... optionals)
url
- String, The URL to request.content
- String, The content to verify with.optionals
- SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
String url = "http://rest.api.url";
String content = "the content returned by url";//for verification
//Get content of url and wait for response with timeout 60 seconds, and verify with content.
if(Misc.VerifyURLContent(url, content, "60")){
System.out.println("content of url '"+url+"' matches with content '"+content+"'.");
}
//Get content of url with headers ("Accept", "text/*") and ("Accept-Charset", "UTF-8")
//and wait for response with default timeout 120 seconds, then verify with content.
if(Misc.VerifyURLContent(url, content, "", "Accept", "text/*", "Accept-Charset", "UTF-8" )){
System.out.println("content of url '"+url+"' matches '"+content+"'.");
}
public static boolean VerifyURLToFile(java.lang.String url, java.lang.String file, java.lang.String... optionals)
url
- String, The URL to request.file
- String, The name of the bench file holding the content to be compared with the response sent back from the server.
The bench file can be a full path, a relative path, or a file name.
For relative path, it is appended to the project's path to build the full path of the file.
For file name, the file is supposed under the project's bench directory (it is Datapool\Bench in SAFS or Benchmarks in SE+).
In any case the parent folder of the file must exist.optionals
- SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
String url = "http://rest.api.url";
String file = "content.html";//for verification
//Get content of url and wait for response with timeout 60 seconds, and verify with a file.
if(Misc.VerifyURLToFile(url, file, "60")){
System.out.println("content of url '"+url+"' matches with file '"+file+"'.");
}
//Get content of url with headers ("Accept", "text/*") and ("Accept-Charset", "UTF-8")
//and wait for response with default timeout 120 seconds, then verify with a file.
if(Misc.VerifyURLToFile(url, file, "", "Accept", "text/*", "Accept-Charset", "UTF-8" )){
System.out.println("content of url '"+url+"' matches with file '"+file+"'.");
}
public static boolean WaitForGUI(Component comp, long time)
comp
- -- Component (from generated Map.java)time
- - time in second
WaitForGUI(Map.Google.SignIn,10);
public static boolean WaitForGUI(Component component, java.lang.String... optionals)
component
- Component, The component to wait.optionals
- SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
//wait for at the most 15 seconds until Basc_Button becomes valid.
Misc.WaitForGUI(Map.SAPDemoPage.Basc_Button);
//wait for at the most 2 seconds until Basc_Button becomes valid.
Misc.WaitForGUI(Map.SAPDemoPage.Basc_Button, "2");
public static java.lang.String OnGUIExistsGotoBlockID(Component component, java.lang.String blockid, java.lang.String... optionals)
Note: SAFSPlus user does not call this API directly. If it is called, the return code could be used to tell if the component exist or not.
component
- Component, The component to checkblockid
- String, the BLOCKID to branchoptionals
- SAFSPlus.Misc.IsComponentExists(org.safs.model.Component, String...)
public static java.lang.String OnGUINotExistGotoBlockID(Component component, java.lang.String blockid, java.lang.String... optionals)
Note: SAFSPlus user does not call this API directly. If it is called, the return code could be used to tell if the component exist or not.
component
- Component, The component to checkblockid
- String, the BLOCKID to branchoptionals
- public static boolean WaitForGUIGone(Component component, java.lang.String... optionals)
component
- Component, The component to wait its gone.optionals
- SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
//wait for at the most 15 seconds until Basc_Button becomes invalid.
Misc.WaitForGUIGone(Map.SAPDemoPage.Basc_Button);
//wait for at the most 2 seconds until Basc_Button becomes invalid.
Misc.WaitForGUIGone(Map.SAPDemoPage.Basc_Button, "2");
public static boolean WaitForPropertyValue(Component component, java.lang.String propertyName, java.lang.String expectedValue, java.lang.String... optionals)
component
- Component, The component to wait for its property matching.propertyName
- String, Case-sensitive name of object property to watch.expectedValue
- String, Case-sensitive value of the object property to match.optionals
- String
SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
Misc.WaitForPropertyValue(Map.windowName.componentName, "propertyValue", "expectedValue");
2. Wait for the property value matching with expected value with 20 seconds.
Misc.WaitForPropertyValue(Map.windowName.componentName, "propertyValue", "expectedValue", "20");
3. Wait for the property value matching with expected value with 20 seconds and compare case sensitively.
Misc.WaitForPropertyValue(Map.windowName.componentName, "propertyValue", "expectedValue", "true");
public static boolean WaitForPropertyValueGone(Component component, java.lang.String propertyName, java.lang.String expectedValue, java.lang.String... optionals)
component
- Component, The component to wait for its matching property gone.propertyName
- String, Case-sensitive name of object property to watch.expectedValue
- String, Case-sensitive value of the object property to match.optionals
- String
SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
Misc.WaitForPropertyValueGone(Map.windowName.componentName, "propertyValue", "expectedValue");
2. Wait for the property value gone with expected value with 20 seconds.
Misc.WaitForPropertyValueGone(Map.windowName.componentName, "propertyValue", "expectedValue", "20");
3. Wait for the property value gone with expected value with 20 seconds and compare case sensitively.
Misc.WaitForPropertyValueGone(Map.windowName.componentName, "propertyValue", "expectedValue", "true");
public static boolean WaitForRegistryKeyExists(java.lang.String key, java.lang.String... optionals)
key
- String, The Registry Key name to seek.optionals
- SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
String key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment";
String value = "CurrentVersion";
String result = null;
if(Misc.WaitForRegistryKeyExists(key, value)){
result = Misc.GetRegistryKeyValue(key, value);
}
public static boolean WaitForRegistryKeyValue(java.lang.String key, java.lang.String value, java.lang.String expectedValue, java.lang.String... optionals)
key
- String, The Registry Key name to seek.value
- String, The value name under the parent key to seek.expectedValue
- String,Case-sensitive value to match with the key value.optionals
- SAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
String key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment";
String value = "CurrentVersion";
String expectedValue = "1.7";
//Wait 'HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment:CurrentVersion' to be "1.7"
//Program will continue if the value is not detected as "1.7" within timeout 2 seconds.
if(Misc.WaitForRegistryKeyValue(key, value, expectedValue, "2")){
System.out.println(key+":"+value+" equals to "+expectedValue);
}
Copyright © SAS Institute. All Rights Reserved.