Forum Discussion

Bro's avatar
Bro
New Contributor
14 years ago

Completing TextBoxes with values from csv file using script.

Hello,



I'm new to TestComplete and I would like You to help m with an issue. The thing is that I have a .NET winform with several textboxes and I need to write a test that would fill them with data read from csv file. Can this be done in script? Prefferably C# script. Thank You in advance for any help.

10 Replies

  • Hi,



    You need to use code like this:

    ...

    var drv = // Create a new DDT driver

    var wnd = // Obtain the window which contains text boxes



    while(!drv["EOF"]())

    {

    wnd.textBox1.Keys(drv["Value"]("textBox1Value"));

    //...

    wnd.textBoxN.Keys(drv["Value"]("textBoxNValue"));

    drv["Next"]();

    }

    ...




    BTW, see the Using DDT Drivers help topic.
  • Bro's avatar
    Bro
    New Contributor
    Thank you for the reply but I'm stuck on the window obtaining. Should it be something like this: form1 = testApp["Form1"]; ? If I put something like this I don't have access to the textboxes in the form. The code I have written according to what you suggested looks like this:


    var  testCompleteApp;

      var  form1;

      var drv = DDT["CSVDriver"]("C:\\Test.csv"); 

      TestedApps["TestCompleteApp"]["Run"](1, true);

      testCompleteApp = Aliases["TestCompleteApp"];

      form1 = testCompleteApp["Form1"];

      while(!drv["EOF"])

      {

        form1.textBox1.Keys(drv["Value"]("textBox1Value"));

        drv["Next"]

      }

      form1["Close"]();
  • Hi,



    By 'form', I mean the window in which text boxes are located. You can find its name by inspecting it in the Object Browser. Also, text box names and DDT column names I used in my script are just to demonstrate the idea. In your application and your CSV file, these values will be different.
  • Bro's avatar
    Bro
    New Contributor
    To see the window in the object browser I have to have application running right?
  • Bro's avatar
    Bro
    New Contributor
    Ok I got it but when I can't find the property Keys for the textBox object. When I type it in I get an error t\saying that this object does not suppert the property or method.
  • Hi,



    Keys is a standard method, all objects in the object tree have it. Is the object, whose Keys method you're trying to call, found?
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Derek,



    Something like this (untested plain translation):

    Dim drv

    Dim wnd



    Set drv = ' Create a new DDT driver

    Set wnd = ' Obtain the window which contains text boxes



    While(Not drv.EOF())

      wnd.textBox1.Keys(drv.Value("textBox1Value"))

      '...

      wnd.textBoxN.Keys(drv.Value("textBoxNValue"))

      drv.Next()

    Wend
  • scristian_1's avatar
    scristian_1
    Occasional Contributor
    Hello,



    Can you help me with an example for JScript?



    Best regards,

    Cristian