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

Random Text

3 Answers 93 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kay
Top achievements
Rank 1
Kay asked on 06 Sep 2017, 07:05 AM

Hello, 

I try to use your code in the tutorial , which is :

int length = 8;
//Define the included characters
string charSet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

Random random = new Random();
string randomText = new String(Enumerable.Repeat(charSet, length).Select(set => set[random.Next(set.Length)]).ToArray());

Find.ById<HtmlInputText>("search-cif").Text = randomText;
Find.ById<HtmlInputSubmit>("img-search-cif").Click();

 

But there's no random text generated and it keep failed.

Error :

Object reference not set to an instance of an object.

 

Can i know why or how im supposed to use the code ?

3 Answers, 1 is accepted

Sort by
0
Kay
Top achievements
Rank 1
answered on 06 Sep 2017, 07:09 AM

As u can see i was trying to generate a random text in the text box . 
Please see attachment . 

 

Thank you.

0
Kay
Top achievements
Rank 1
answered on 06 Sep 2017, 07:10 AM

As you can see, i was trying to create a random text to fill up the text box. 
Please see attachment for details .

Thank you,

0
Accepted
Elena
Telerik team
answered on 07 Sep 2017, 10:36 AM
Hello Kay,

Thank you for the shared details. 

The attachment you wanted to share was not successfully attached. Probably you should zip it t be able to send it. 

Anyways, I reviewed the code you have used and I suppose that the text is generated but the text field causes troubles actually. You could use the following to ensure the text is generated. 
Manager.Log.WriteLine(randomText);

This will right the text into the execution log of the test. You could also include assert statements after the find element statements to ensure these are actually located. You might need to include some delays so that the elements on page are located. 

System.Threading.Thread.Sleep(1000);

I hope these will be helpful for you to find out what is not working in your code. As per the errors listed in the log you would need to debug the implemented custom code and adjust it to the application under test. 

Thank you for your understanding! 

Regards,
Elena Tsvetkova
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Kay
Top achievements
Rank 1
Answers by
Kay
Top achievements
Rank 1
Elena
Telerik team
Share this question
or