Clearing Cookies
Another feature of the test object is to clear cookies when specified.
The testObj property .clearCookieSetting can be set by the $clearCookieOptions variable, which has these options:
.domain
.locale
.urlPath
.urlParameter
.all
.none
The testObj property .clearCookieSetting can be set by the $clearCookieOptions variable, which has these options:
.domain
.locale
.urlPath
.urlParameter
.all
.none
For example:
$checkContact.clearCookieSetting = $clearCookieOptions.all;
It essentially runs the clearCookies() function whenever there is a change in the specified setting, such as before a new locale.
$checkContact.clearCookieSetting = $clearCookieOptions.all;
It essentially runs the clearCookies() function whenever there is a change in the specified setting, such as before a new locale.
Launch.sah and fmReports.sah settings
On the launch.sah file you will find code in 2 parts: the first are settings, and the second are the actual test function calls.
$REPORT_NAME = "Your Report"; $TEST_REPORT_FOLDER_NAME = "YourReport"; $TEST_REPORT_FOLDER_URL = "https://drive.google.com/yourUrl"; //$SEND_EMAIL_EVERY_ISSUE = false; //$TURN_ON_SCREENSHOTS = true; updateReportInfo(); //optionally override the "to" email address list: $EMAIL_ADDRESS = "[email protected]"; //optionally override the test report history to use the "practice" folder: //$TEST_REPORT_FOLDER_NAME = "practice"; updateReportInfo();
Essentially, this means you can override the default settings from the fmReports.sah file with custom settings unique for each launch file, which means unique for every test.
The fmReports.sah file has additional settings, and they also can be overridden on each launch.sah file.
You may want to have a separate launch.sah file for each test environment, such as launch2.sah, launch3.sah, etc.
The last line, $TEST_REPORT_FOLDER_NAME = "practice", is especially usefully to enable while troubleshooting.
Restart Functions
There are 3 settings in fmReports.sah regarding restarting Sahi.
$RESTART_UPON_SCRIPT_CRASH = true;
$ENABLE_SCRIPT_RESTART_CHECK = true;
$CRASH_MAX_RESTARTS = 3;
The first one $RESTART_UPON_SCRIPT_CRASH can be set on the launch.sah file, and it will re-launch Sahi without any limit if enabled --even for a syntax error, so use with caution.
Sahi Pro offers the ability to write to a file, so we can pick up where the last test ended with these two options:
$ENABLE_SCRIPT_RESTART_CHECK = true;
$CRASH_MAX_RESTARTS = 3;
IMPORTANT: the setting for $ENABLE_SCRIPT_RESTART_CHECK must be set on the actual fmReports.sah file in order to work.
The $CRASH_MAX_RESTARTS setting can be individually set on each launch.sah file, as desired.
To restart a test approximately where the previous incomplete test stopped, utilize these functions:
ifRestartUpdateStartingLocale($yourTestObj);
ifRestartUpdateStartingUrlPath($yourTestObj);
ifRestartUpdateStartingUrlParameter($yourTestObj);
In the testSample folder, you will find this code:
ifRestartUpdateStartingLocale($checkContact);
This will restart the test at the beginning of the "/mx" urls if for some reason the test fails during those MX tests. This is especially useful if you have a lot of locales you are rotating through, and if the "150 second" error somehow is causing your script to crash before completing. Typically only one of the "ifRestart" functions should be used per test.
See the fmReports.sah file for details on how to set this up.
$RESTART_UPON_SCRIPT_CRASH = true;
$ENABLE_SCRIPT_RESTART_CHECK = true;
$CRASH_MAX_RESTARTS = 3;
The first one $RESTART_UPON_SCRIPT_CRASH can be set on the launch.sah file, and it will re-launch Sahi without any limit if enabled --even for a syntax error, so use with caution.
Sahi Pro offers the ability to write to a file, so we can pick up where the last test ended with these two options:
$ENABLE_SCRIPT_RESTART_CHECK = true;
$CRASH_MAX_RESTARTS = 3;
IMPORTANT: the setting for $ENABLE_SCRIPT_RESTART_CHECK must be set on the actual fmReports.sah file in order to work.
The $CRASH_MAX_RESTARTS setting can be individually set on each launch.sah file, as desired.
To restart a test approximately where the previous incomplete test stopped, utilize these functions:
ifRestartUpdateStartingLocale($yourTestObj);
ifRestartUpdateStartingUrlPath($yourTestObj);
ifRestartUpdateStartingUrlParameter($yourTestObj);
In the testSample folder, you will find this code:
ifRestartUpdateStartingLocale($checkContact);
This will restart the test at the beginning of the "/mx" urls if for some reason the test fails during those MX tests. This is especially useful if you have a lot of locales you are rotating through, and if the "150 second" error somehow is causing your script to crash before completing. Typically only one of the "ifRestart" functions should be used per test.
See the fmReports.sah file for details on how to set this up.
Run the Test
There are 2 methods to actually run the testObj: .run() and .testUrls($list).
The obvious way to run a testObj test is with .run().
For example, this is taken from the testSample launch.sah file: $checkContact.run();
But if you need to test the test and give specific URLs to represent each specific test scenario, use the .testUrls method:
//to test with a specific list of urls, use .testUrls:
var $urlList = [
"http://www.inspyder.com/products/InSite/Broken-Link-Checker",
"http://www.this-page-intentionally-left-blank.org/",
"http://www.openallurls.com/",
"http://libreoffice.org"
];
$checkContact.testUrls($urlList);
The obvious way to run a testObj test is with .run().
For example, this is taken from the testSample launch.sah file: $checkContact.run();
But if you need to test the test and give specific URLs to represent each specific test scenario, use the .testUrls method:
//to test with a specific list of urls, use .testUrls:
var $urlList = [
"http://www.inspyder.com/products/InSite/Broken-Link-Checker",
"http://www.this-page-intentionally-left-blank.org/",
"http://www.openallurls.com/",
"http://libreoffice.org"
];
$checkContact.testUrls($urlList);
Custom Assertions
These custom assertions will automatically set the "expected" and "observed" values in fmReports, and you can even add an optional test name as a label:
assertExists($element, $testLabel)
assertNotExists($element, $testLabel)
assertEqual($expected,$observed,$testLabel)
assertTrue($observedBooleanValue,$testLabel)
assertMatch($expectedRegEx,$observedStr,$testLabel)
If you want to use a typical sahi assertion, such as _assertEqualImages, all you need to do is use this function before the assertion:
setReport($expected,$observed,$label);
For example:
var $expected = "123";
var $observed = "321"
var $label = "assertion test";
setReport($expected,$observed,$label);
_assertEqual($expected,$observed);
assertExists($element, $testLabel)
assertNotExists($element, $testLabel)
assertEqual($expected,$observed,$testLabel)
assertTrue($observedBooleanValue,$testLabel)
assertMatch($expectedRegEx,$observedStr,$testLabel)
If you want to use a typical sahi assertion, such as _assertEqualImages, all you need to do is use this function before the assertion:
setReport($expected,$observed,$label);
For example:
var $expected = "123";
var $observed = "321"
var $label = "assertion test";
setReport($expected,$observed,$label);
_assertEqual($expected,$observed);
Custom navigation command
For your urls to show up in "URLs tested", it is necessary to use a custom navigation command:
navigate($url);
This is the same as _navigateTo("url",true) except it will store your url for the report's list.
The "fmReports-TestReports" folder
After unzipping the download, you should place the fmReports-TestReports folder directly in the Google Drive (or Sharepoint, etc) online drive folder. You can then copy and paste the report template folder for every corresponding test.
addHeaderIntoURLHistory
If you want to segregate sections in the URL history according to test function, you can add a header between function calls with this:
addHeaderIntoURLHistory("Message");
For example:
testLinks();
addHeaderIntoURLHistory("URLs for the image test");
testImages();
addHeaderIntoURLHistory("Message");
For example:
testLinks();
addHeaderIntoURLHistory("URLs for the image test");
testImages();