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

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

2 Answers 151 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Konstantin
Top achievements
Rank 1
Konstantin asked on 19 Mar 2013, 10:42 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Himanshu
Top achievements
Rank 2
answered on 20 Mar 2013, 10:26 AM
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.








0
Accepted
Cody
Telerik team
answered on 22 Mar 2013, 09:35 PM
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
Tags
General Discussions
Asked by
Konstantin
Top achievements
Rank 1
Answers by
Himanshu
Top achievements
Rank 2
Cody
Telerik team
Share this question
or