Help understand Assert.IsTrue(ActiveBrowser.ContainsText(...));

3 posts, 2 answers
  1. Konstantin
    Konstantin avatar
    11 posts
    Member since:
    Oct 2012

    Posted 19 Mar 2013 Link to this post

    Can somebody please explain what exactly this code statement from the tutorial does:

        Assert.IsTrue(ActiveBrowser.ContainsText(Data[
    "Col1"].ToString()));

    I understand Data["Col1"].ToString() - this is the way to access data for the data bound test.

    ActiveBrowser.ContainsText - what it actually is? Browser caption text? All texts in all tabs of the active browser? What?

    Assert.IsTrue() - what exactly it does? What happens if its parameter is true or false? Is it how Validation logic is presented in the code? But we should be able to branch on validation statement. Can we branch on Assert.IsTrue ?

    Thank you!
    Konstantin

  2. Answer
    Himanshu
    Himanshu avatar
    5 posts
    Member since:
    Oct 2012

    Posted 20 Mar 2013 Link to this post

    Hi

    Lets take your questions one by one:

    1)ActiveBrowser.ContainsText - what it actually is? Browser caption text? All texts in all tabs of the active browser? What?

    This function works like Ctrl +f on a browser i.e. it looks for the text on what is displayed on screen for that page. So if the text is on that page, it returns a Boolean true else false.

    2)Assert.IsTrue() - what exactly it does?What happens if its parameter is true or false? Is it how Validation logic is presented in the code?

    This Function passes a test if the parameter passed is a Boolean 'True' and fails it if it is Boolean 'False'. So, yes, this is how we use validations in code.

    3) Can we branch on Assert.IsTrue ?

    I am not sure what you mean by branching. If it is using it in If statement, then the answer is that use the parameter being passed for that. Like you can use if the  ActiveBrowser.ContainsText returns a true then do this else that.

    Hope it helps.








  3. Answer
    Cody
    Admin
    Cody avatar
    3354 posts

    Posted 22 Mar 2013 Link to this post

    Hello,

    Thank you Himanshu for jumping in and assisting. I've granted you some Telerik points to say thank you.

    Can we branch on Assert.IsTrue ?

    No it's not intended for that. Test Studio will evaluate the expression you place inside the ( ). If the expression evaluates to True the test will continue on to the next line of code. If the expression evaluates to False an Exception will be thrown causing the test to immediately stop/abort. Test Studio will add a stack trace to the test log which will identify the line of code that threw the exception (the Assert statement in this case).

    All the best,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top