Forum Discussion

subhram_sahoo's avatar
subhram_sahoo
Occasional Contributor
2 years ago

how to handle multi line in test complete python script

S2F33_DefineReport_Job: 'S2F33' W
<L[2]
<U2[1] 1> /* DATAID */
<L[1]
<L[2]
<U4[1] 8010> /* RPTID */
<L[2]
<U4[1] 8010> /* Clock */
>
>
>
>.")

need exact this format

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    You want to use Keys to write multiple lines? Then you need to have the carriage return key '\r' or line break '\n' on each line.

     

    For example,

    var str1 = "Hello\rWorld";
    var str2 = "Hello\nWorld";
    var str3 = "Hello\r\nWorld";
    
    // Which will print
    
    Hello
    
    World

     

     

    • subhram_sahoo's avatar
      subhram_sahoo
      Occasional Contributor

      Can we connect through skypee. Above approach was not what i am looking

    • subhram_sahoo's avatar
      subhram_sahoo
      Occasional Contributor

      I have to pass this things as an input as key word driven. I go through the information shared in above link but did not find any solutions from there.

       Aliases.*****_****_Utilities_SecsTestApp.HwndSource_MainWindow.MainWindow.textBoxMsgToSend.keys("S2F33_DefineReport_Job: 'S2F33' W
      <L[2]
      <U2[1] 1> /* DATAID */
      <L[1]
      <L[2]
      <U4[1] 8010> /* RPTID */
      <L[2]
      <U4[1] 8010> /* Clock */
      >
      >
      >
      >.")

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I was not aware that those were array values, as you did not mention it. However, you will need to construct a string like so,

    function test10()
    {
        var L = [1, 2, 3];
        var U2 = ["A", "B", "C"];
    
        var str =
            "S2F33_DefineReport_Job: 'S2F33' W" +
            "<" + L[2] +
            "<" + U2[1] + "1> /* DATAID */";
            
        Log.Message(str); // Output string to see if format is correct
    }

     

    See https://stackoverflow.com/questions/7975005/format-a-javascript-string-using-placeholders-and-an-object-of-substitutions for substitutions values.

     

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    So you don't want to use Keys to write muliple lines?

     

    Would it be possible to explain exactly what you are trying to do, so that I can understand better, and provide a solution?

    • subhram_sahoo's avatar
      subhram_sahoo
      Occasional Contributor

      i want to execute below script to my desktop application. 

      Aliases.*****_****_Utilities_SecsTestApp.HwndSource_MainWindow.MainWindow.textBoxMsgToSend.keys("S2F33_DefineReport_Job: 'S2F33' W
      <L[2]
      <U2[1] 1> /* DATAID */
      <L[1]
      <L[2]
      <U4[1] 8010> /* RPTID */
      <L[2]
      <U4[1] 8010> /* Clock */
      >
      >
      >
      >.")

      but unable to do as test complete show syntax error when i put the text mentioned above. because i need above text in my app as it is to execute and get some data. in above text there are space also

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Here's script code to enter mutlple lines in a text area,

    function testarea()
    {
        // https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_textarea
        var browser = Sys.Browser("chrome");
        var page = browser.Page("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_textarea");
        var textarea = page.Panel("container").Panel("iframecontainer").Panel("iframe").Panel("iframewrapper").Frame("iframeResult").Form(0).Textarea("w3review");
        textarea.Keys("~a[Del]");
        textarea.Keys("S2F33_DefineReport_Job: 'S2F33' W\r<L[2]\r<U2[1] 1> /* DATAID */\r<L[1]\r<L[2]\r<U4[1] 8010> /* RPTID */\r<L[2]\r<U4[1] 8010> /* Clock */\r>\r>\r>\r>.");
    }

    Which is in the same format.

    • subhram_sahoo's avatar
      subhram_sahoo
      Occasional Contributor

      in above way i wrote. but its not taking the value inside [] bracket.

      ex- 

      L[2]
      U2[1] 
      U2[1] 

       

      its only displaying L and U2. Not the value 2 and 1 inside [] bracket