Hi Team,
I need to put the assertion and logSuccess result only in text file at run time.
to handle xvz myObj1,myObj2
Try
put {Text:myObj1} into ObjLocation
log everyimagelocation (Text:myObj)
if the number of items in ObjLocation >= 1
then
assert [ObjLocation.Text] equals myObj2 with error
end if
Catch theException
log "assertion failed as value on Screen is" && [ObjLocation.Text]&&"expected value is"&& myObj2
End try
end xyz
Hello Vishal,
myObj is an undefined variable in your code, so I do not know what you intend with the line
log everyimagelocation(Text:myObj)
I am wagering that you intended to use myObj1 on that line. I am also uncertain what the relationship between myObj1 and myObj2 is supposed to be. Is myObj2 text that you expect to see on the screen, but if you see the text myObj1 on the screen, the script should fail, even if myObj2 is visible? Are myObj1 and myObj2 blocks of text that will never appear on the screen at the same time? Below is my code written based on the following assumptions:
- myObj1 is text that you do NOT want to see in the SUT.
- myObj2 is text that you DO want to see in the SUT.
- If myObj1 is NOT visible on the screen, assume that myObj2 is visible on the screen.
- If myObj1 is visible on the screen, the text file should contain the word TRUE.
- If myObj1 is NOT visible on the screen, the text file should contain myObj1 && “was NOT visible on the screen.”
Based on those 5 assumptions, here is my code. You can test it with the TutorialSUT available by following these instructions: Using the Eggplant Functional Connection List | EPF Docs
The script will FAIL if the Favorites screen is displayed but PASS if the Contacts screen is displayed.
Put "Still" into myObj1 -- if this text is present on the SUT, the script fails
Put "tap" into myObj2 -- if the text of myObj1 is not present on the SUT, this text will be
Put FindSomeText(myObj1,myObj2) into file ResourcePath("results.txt")
function FindSomeText myObj1, myObj2
if ImageFound(text:myObj1) then
put TRUE into myValue
else
put myObj1 && "was NOT visible on the screen, therefore" && myObj2 && "must have been present" into myValue
end if
Return myValue
end FindSomeText
Hope this helps,
Dave
I am passing the myObj1,myObj2 values from the function called from the main script.
And I want to append the text file (result.txt) having result of assertion and logSuccess used in the function/handler at runtime.
Hope you are clear.
Hi Vishal,
I would recommend that you work with the TCSM who is assigned to you. Without seeing more of your code and the values of myObj1 and myObj2 and what your LogSuccess command looks like, I cannot recommend anything beyond the code that I have already posted.
Thanks,
Dave
Hey @vishaljindal0804,
Check out these doc pages they will guide you how to write data to a file.
Open File
write to file
you can also change the “opening mode” to appending which will add all the logging by default at the end of the file.
For the assert command you can get the result status counts with these commands assert
another option is to use try and catch
Example:
put resourcepath("abx.txt") into MyFileVar // creates a variable with a path to a file
open file MyFileVar // opens the file
put "GIO NOW" into MyWrite // puts a text string into a variable
write "abs"&return to file MyFileVar at eof // adds a return character to the end of the file to ensure that new writes begin on a new line
write MyWrite to file MyFileVar // writes the text from the variable into the file
close file MyFileVar // closes the file
put file MyFileVar // prints file content
enhanced @DaveHester 's example:
Put "Still" into myObj1 -- if this text is present on the SUT, the script fails
Put "tap" into myObj2 -- if the text of myObj1 is not present on the SUT, this text will be
set MyFile to ResourcePath("results.txt")
open file MyFile -- only needs to be performed once
write FindSomeText(myObj1,myObj2)&CRLF into file MyFile at eof -- will add the returned values from the function FindSomeText to the file
close file MyFile -- this can be done at the end of you script
function FindSomeText myObj1, myObj2
if ImageFound(text:myObj1) then
put TRUE into myValue
else
put myObj1 && "was NOT visible on the screen, therefore" && myObj2 && "must have been present" into myValue
end if
Return myValue
end FindSomeText
Let us know in case you have further questions.
Cheers,
Karsten