What does Assert.IsNotNull return?

4 posts, 1 answers
  1. Nigel
    Nigel avatar
    53 posts
    Member since:
    Jan 2012

    Posted 01 Mar 2012 Link to this post

    Hi,

    Anthony provided what looks like a nice solution to a problem I raised (http://www.telerik.com/automated-testing-tools/community/forums/test-studio/general-discussions/finding-and-clicking-dynamic-buttons.aspx), but when I try to implement it my script fails to run.  The log shows this error:

    WaitForLogoutButtonAvailable.tstest.vb: Line 81: (BC30491) Expression does not produce a value.
    This is the VB sub:

            Public Sub WaitForLogoutButtonAvailable_CodedStep()
                Dim found As Integer = 0
                Dim s As HtmlSpan = Find.ByExpression(Of HtmlSpan)("textcontent=~logout")
                While found = 0
                    If (Assert.IsNotNull(s)) Then
                        'Stop looking
                        found = 1
                    Else
                        'Wait for '250' msec.
                        System.Threading.Thread.Sleep(250)
                    End If
                End While
            End Sub

    I tried exchanging the statement:
         If (Assert.IsNotNull(s)) Then
    for:
         If (Assert.IsNotNull(s) = true) Then
    but I get the same result.  I also tried with various speechamrks, 1's and 0's.  I read the on-line documentation (http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/write-tests-in-code/intermediate-topics/html-control-suite/html-asserts.aspx, and also http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/write-tests-in-code/intermediate-topics/element-identification/findparam-objects.aspx) but the pages don't actually show me what is returned by the assert.

    Where am I going wrong?

    Thanks,
    Nigel Edwards, Transition Computing

     
  2. Nigel
    Nigel avatar
    53 posts
    Member since:
    Jan 2012

    Posted 01 Mar 2012 Link to this post

    Out of ignorance I also tried this sub but got the same error:

            Public Sub WaitForLogoutButtonAvailable_CodedStep()
                Dim s As HtmlSpan = Find.ByExpression(Of HtmlSpan)("textcontent=~logout")
                While Not Assert.IsNotNull(s)
                    System.Threading.Thread.Sleep(250)
                    s = Find.ByExpression(Of HtmlSpan)("textcontent=~logout")
                End While
            End Sub

    Thanks.
  3. Answer
    Cody
    Admin
    Cody avatar
    3360 posts

    Posted 01 Mar 2012 Link to this post

    Hi Nigel,

    I am sorry for the confusion. The Assert.xxxx functions do not return any value at all. As a result they cannot be used in IF statements as you're trying to do. The purpose of the Assert class is it will throw an exception (which will immediately abort the test) if the condition being tested is not true. In other words Assert.IsNotNull(s) will throw an exception and make the test immediately abort if s is null. Else the test will continue to run normally.

    If you can explain what you're trying to accomplish with your code perhaps we can offer you a better solution to what you've attempted to code.

    All the best,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  4. Nigel
    Nigel avatar
    53 posts
    Member since:
    Jan 2012

    Posted 02 Mar 2012 Link to this post

    Aha,  I see!  Okay, now I know how assert works I can see how useful and powerful it is.  I will leave this for now, as I have managed to get the services of a developer who, with his great experience, is helping me to understand how I should be scripting.  Thanks for all your help, Anthony, and be assured that if we come up with any problems we can't resolve I'll be back on the forum again!  :)
Back to Top