This is a migrated thread and some comments may be shown as answers.

What does Assert.IsNotNull return?

3 Answers 179 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nigel
Top achievements
Rank 2
Nigel asked on 01 Mar 2012, 11:35 AM
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

 

3 Answers, 1 is accepted

Sort by
0
Nigel
Top achievements
Rank 2
answered on 01 Mar 2012, 12:38 PM
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.
0
Accepted
Cody
Telerik team
answered on 02 Mar 2012, 01:08 AM
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
0
Nigel
Top achievements
Rank 2
answered on 02 Mar 2012, 10:42 AM
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!  :)
Tags
General Discussions
Asked by
Nigel
Top achievements
Rank 2
Answers by
Nigel
Top achievements
Rank 2
Cody
Telerik team
Share this question
or