Forum Discussion

maumrm's avatar
maumrm
Contributor
3 years ago

Copy and paste text from Variable

For an online application I have html fields which do not include the "max length" or "set text" methods. That leaves me with keying in characters to verify the max length allowed, which is not fast since the database limits are 4,000 characters. Is there a way within Keyword tests to copy the text of a project variable and then paste that into the field? Any other suggestions?

 

Thanks!

  • I was able to do this by opening using the notepad as a TestedApp. A file with the text is opening, copied from the TestedApp, and then pasted into the application, then the TestedApp gets closed.

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Is there a way within Keyword tests to copy the text of a project variable and then paste that into the field?

    Most probably, you will have to use the RunCodeSnippet operation, and you may consider copying/pasting into field from clipboard as a possible option.
    Something like this in pseudo-code:

     

    var oField = ... // set a reference to the required field
    oField.Click(); // this will set a focus to a field
    oField.Keys("^[Home][P200]^![End][Del]"); // select all text in a field and delete it. "^A[Del]" might work as well
    var strValue = getRandomString(5000); // your custom function that will return 5000 characters-long random string
    var oClp = Sys.Clipboard; // preserve current value of clipboard
    Sys.Clipboard = strValue; // stores strValue into clipboard. This line of code must immediately precede the next one to lower the chance of clipboard content corruption
    oField.Keys("^V"); // paste from the clipboard via Ctrl-V shortcut
    Sys.Clipboard = oClp; // restore clipboard
    var strActualValue = oField.wText; // get actual value from a field
    // do whatever verifications against strValue and strActualValue

     

     

    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      Thanks to everyone in this thread!

       

      Hi maumrm! Please let us know if your question is solved - you can do this by marking the best reply as a solution. 

  • Hi maumrm 

     

    Are you using On Screen Action or Call Object Method operations? Call Object Method may have the methods you need.

     

    If not, use the Object Spy in Advanced mode to list out all of the properties of the object, then you might be able to use a Call Object Method OR a code snippet using the SetAttributes method using a project variable as the value to set.

  • I was able to do this by opening using the notepad as a TestedApp. A file with the text is opening, copied from the TestedApp, and then pasted into the application, then the TestedApp gets closed.