Random Text

4 posts, 1 answers
  1. Kay
    Kay avatar
    5 posts
    Member since:
    Aug 2017

    Posted 06 Sep 2017 Link to this post

    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 ?

  2. Kay
    Kay avatar
    5 posts
    Member since:
    Aug 2017

    Posted 06 Sep 2017 Link to this post

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

     

    Thank you.

  3. Kay
    Kay avatar
    5 posts
    Member since:
    Aug 2017

    Posted 06 Sep 2017 Link to this post

    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,

  4. Answer
    Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    934 posts

    Posted 07 Sep 2017 Link to this post

    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!
Back to Top