Is there a way to save a file to a local directory for tester to check once test is executed?
I want to save a file from a pop-up and the following sample steps is as follows:
- Click a link
- Observe that a pop-up web browser window is displayed with pages of text in particular format
- Save these texts onto a .txt or .docx with a file name of "test1" onto a desktop (or even a screenshot)
The reason is for the tester to come back and check these files for results of a particular action after the test execution. Is there a way to achieve this?
Hi there.
I wrote sample test case and added custom captions for steps to explain what and why each step does. Test case uses random site in the internet with popup demonstration.
It works for macOS and Windows, doing next:
1) Go to site
2) Click on button to open popup
3) Reads content of the popup
4) Writes content to the text file on Desktop. File name has appended time in the end to understand when execution was done.
Locators, used in test case (create new locator and put the code into locator "Advanced View")
//begin of random.button.popup, don't copy this line
page:random;
type:button;
alias:popup;
id:;
name:;
text:;
css:;
target:;
XPath://input[@value='Open a Popup Window'];
ieXPath:;
ffXPath:;
chromeXPath:;
safariXPath:;
edgeXPath:;
window:;
frame://iframe[@name='result1'];
comments:;
//end of random.button.popup, don't copy this line
//begin of random.div.popup_div_text, don't copy this line
page:random;
type:div;
alias:popup_div_text;
id:;
name:;
text:;
css:;
target:;
XPath://div[@class="main"];
ieXPath:;
ffXPath:;
chromeXPath:;
safariXPath:;
edgeXPath:;
window:Popup Example;
frame:;
comments:;
//end of random.div.popup_div_text, don't copy this line
Test case (create new one and put the JSON below to "Advanced View" after locators are created):
//start, don't copy this line
{
"steps" : [
{
"index" : 1,
"key" : "SET_DATE",
"model" : {
"source" : "@System.date",
"sourceFormat" : null,
"targetFormat" : "dd_MM___hh_mm_ss",
"offset" : "",
"escape" : [ ],
"variable" : "time_postfix"
},
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : "File name postfix is created based on current date. Required if you plan to run a lot of tests without instant file delete."
},
{
"index" : 2,
"key" : "SET_VAR",
"model" : {
"variableName" : "relative_path",
"sourceType" : "STATIC",
"value" : {
"encrypted" : false,
"raw" : "Desktop/result_file_@time_postfix.txt"
},
"alphabet" : null,
"regex" : null,
"expressionLength" : 0
},
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : "Create relative file path including postfix from previous time. Contains \"desktop\" folder name too."
},
{
"index" : 3,
"key" : "GOTO_URL",
"model" : {
"url" : "https://www.quackit.com/javascript/popup_windows.cfm"
},
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : "Go to the site where you want to open popup"
},
{
"index" : 4,
"key" : "CLICK",
"model" : {
"locator" : "random.button.popup"
},
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : "Click on button to open popup."
},
{
"index" : 5,
"key" : "GET_WEB_VALUE",
"model" : {
"variableName" : "popup_text",
"script" : null,
"sourceType" : "LOCATOR",
"xmlType" : "{http://www.w3.org/1999/XSL/Transform}NODE",
"timestampEnabled" : false,
"timeStampSeparator" : null,
"excludeCharacters" : [ ],
"attribute" : "TEXT",
"pseudoElement" : null,
"colorAsHex" : false,
"locator" : "random.div.popup_div_text"
},
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : "Get popup text. If popup with text doesn't exist, test case will fail on this step."
},
{
"index" : 6,
"key" : "IF",
"model" : {
"operator" : "EQUAL",
"comparisonType" : "TEXT",
"caseSensitive" : false,
"leftDateFormat" : null,
"rightDateFormat" : null,
"leftValue" : "@System.os",
"rightValue" : "macOS"
},
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : ""
},
{
"index" : 7,
"key" : "SET_VAR",
"model" : {
"variableName" : "path",
"sourceType" : "STATIC",
"value" : {
"encrypted" : false,
"raw" : "$HOME/@relative_path"
},
"alphabet" : null,
"regex" : null,
"expressionLength" : 0
},
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : "Define full path to file on macOS"
},
{
"index" : 8,
"key" : "EXECUTE_COMMAND",
"model" : {
"args" : [
"/bin/bash",
"-c",
"echo \"@popup_text\" > @path"
]
},
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : "Write popup content to file"
},
{
"index" : 9,
"key" : "ELSE_IF",
"model" : {
"operator" : "EQUAL",
"comparisonType" : "TEXT",
"caseSensitive" : false,
"leftDateFormat" : null,
"rightDateFormat" : null,
"leftValue" : "@System.os",
"rightValue" : "Windows"
},
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : ""
},
{
"index" : 10,
"key" : "SET_VAR",
"model" : {
"variableName" : "path",
"sourceType" : "STATIC",
"value" : {
"encrypted" : false,
"raw" : "%userprofile%\\@relative_path"
},
"alphabet" : null,
"regex" : null,
"expressionLength" : 0
},
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : "Define full path to file on Windows"
},
{
"index" : 11,
"key" : "PRINT",
"model" : {
"message" : "Unfortunately, Windows doesn't support echo with multilines argument. Process text into multiple echo commands"
},
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : ""
},
{
"index" : 12,
"key" : "GET_WEB_VALUE",
"model" : {
"variableName" : "lines_count",
"script" : "return `@popup_text`.split(\"\\n\").length - 1;",
"sourceType" : "JAVA_SCRIPT",
"xmlType" : null,
"timestampEnabled" : false,
"timeStampSeparator" : null,
"excludeCharacters" : [ ],
"attribute" : null,
"pseudoElement" : null,
"colorAsHex" : false,
"locator" : "<NOT SELECTED>"
},
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : "Get count of lines in text"
},
{
"index" : 13,
"key" : "LOOP",
"model" : {
"variableName" : "loop_index",
"from" : "0",
"to" : "@lines_count",
"increment" : "1"
},
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : ""
},
{
"index" : 14,
"key" : "GET_WEB_VALUE",
"model" : {
"variableName" : "single_line",
"script" : "return `@popup_text`.split(\"\\n\")[@loop_index];\nreturn 'echo \"' + line + '\" > @path';",
"sourceType" : "JAVA_SCRIPT",
"xmlType" : null,
"timestampEnabled" : false,
"timeStampSeparator" : null,
"excludeCharacters" : [ ],
"attribute" : null,
"pseudoElement" : null,
"colorAsHex" : false,
"locator" : "<NOT SELECTED>"
},
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : "Get command for single line"
},
{
"index" : 15,
"key" : "EXECUTE_COMMAND",
"model" : {
"args" : [
"cmd",
"/c",
"echo @single_line >> @path"
]
},
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : "Write popup content line to file."
},
{
"index" : 16,
"key" : "LOOP_END",
"model" : { },
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : ""
},
{
"index" : 17,
"key" : "END_IF",
"model" : { },
"skip" : false,
"runtimeOption" : "HALT",
"customCaption" : ""
}
]
}
//end, don't copy this line
Please sign in to leave a comment.