Jump to content

Recommended Posts

Posted

Hi I am trying to see how best to write my scripts. 

I have a function (using the Webdriver). And if the test fails I would like to return fail and if it success I'd like to return success. 

That way in my main script I can do something like 

 

if Func function_TestHeader($sSession) == "Success" Then 
;continue script
Else
;troubleshoot
Endif

Below is my function? Should I be using binary value rather than text? Is there a better way to do it? 

Func function_TestHeader($sSession)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByTagName, 'h2')
_WD_WaitElement($sSession, $_WD_LOCATOR_ByTagName, $sElement)
_WD_HighlightElements($sSession, $sElement)
$textContent = _WD_ElementAction($sSession, $sElement, 'property', 'text')
if $textContent == "New Starters" Then
   WriteToConsoleAndLog("Test Passed: h2 header is correct")
   Return "Success"
Else
WriteToConsoleAndLog("Test Failed: h2 header is incorrect")
WriteToConsoleAndLog("---LOG:$textContent equals: " & $textContent)
Return "Fail"
endif

EndFunc

 

Posted

Usually when a function fails it's good to set the @error macro to know exactly where it fails. Here might be an example of your function:

Local $sRet = function_TestHeader($sSession)
If @error Then
    ConsoleWrite('Something went wrong. Start debug.' & @CRLF)
    ConsoleWrite('Returned value: ' & $sRet & @CRLF)
Else
    ConsoleWrite('Everything is good, continue your script.' & @CRLF)
    ConsoleWrite('Returned value: ' & $sRet & @CRLF)
EndIf

Func function_TestHeader($sSession)
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByTagName, 'h2')
    _WD_WaitElement($sSession, $_WD_LOCATOR_ByTagName, $sElement)
    _WD_HighlightElements($sSession, $sElement)
    $textContent = _WD_ElementAction($sSession, $sElement, 'property', 'text')
    if $textContent == "New Starters" Then
       WriteToConsoleAndLog("Test Passed: h2 header is correct")
       Return SetError(0, 0, 'Success')
    Else
        WriteToConsoleAndLog("Test Failed: h2 header is incorrect")
        WriteToConsoleAndLog("---LOG:$textContent equals: " & $textContent)
        Return SetError(1, 0, 'Fail')
    endif
EndFunc

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...