Katalon Analytics (beta) – Bringing new insights into test reports. Learn more!

Enter a long multi-line text

How can i add multi-line texts in a multi line text field present in my website?

I tried using the set text (that empties the field if something is present there) but if i try to paste the text, only the first line is shown.

Comments

  • Hello, try to add a line separators into a single setText method.
    WebUI.setText(testObject, "first line\nsecondline\nthird line")
  • The thing is, that this website will have text fields that will have up to 600.000 characters (that's the max i've seen so far) but mostly between 100's and 1000's, many of them having multiple lines. It would be nonsense for me to put a separator between every new line ( i want to use real data, not copy pasting 1000 words with separators between them)
  • And how do you want to fill these text fields? Do you have some test data which you take and you want to use them in text fields?
  • Please try this

    Eg:

    def yourText = '''\

    Your text here

    '''

    Thanks.
  • Marek Melocik: We will have to enter predefined texts, always different, but for testing purposes i will use a longer general text.

    duyluong Sorry i don't understand what are you saying.

    When i try to add a Value to the Set text, and paste the text that has new lines (enter) then only the first line get's pasted in that field. As i am typing this i realized that the text is with \n in the dev (f12) response! i will try that, thanks.

     

     
  • no luck, tried to copy texts with /n alsi with the Enter icon (from the Preview in dev mode) but it just writes the characters in the text like "↵This" and /"n This" in a single line.
  • Hi there,

    Based on duyluong answer, please your multiple lines of text into the variable using triple single quoted, then use it, e.g
    def yourText = '''
    line one
    line two
    line three
    ....
    line n
    '''

    WebUI.setText(findTestObject(''), yourText)

    Thanks
  • Ok, all i had was a 1 day training about writing code. What i managed was to make a Keywords package and defined yourText as you said but honestly have no idea how to add that after the setText - text field object - ..? value type ?

    Sorry for my noob-ness
  • Hello. So how do i add this? keyword? could you please attach a pritnscreen?
  • Do you have a sample text so that I can try and give you the screenshot?

    Thanks
  • Let's do it with the classic: http://www.lipsum.com/feed/html - (i think this comment section changes it a bit)

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin congue tempus tempor. Donec pretium viverra eleifend.

    Aliquam et condimentum sem. Sed molestie nisl lectus, eget ultrices lorem tincidunt in. Morbi sed hendrerit dolor. Aliquam erat volutpat.

    Integer maximus ex tempus auctor elementum. Vivamus vel lacus eu ante maximus consequat. Vestibulum lacus eros, gravida in massa ut, malesuada ultricies quam.

    Suspendisse pharetra eros nec auctor posuere. Nunc sit amet dignissim eros. Suspendisse imperdiet tristique massa, id lacinia orci viverra id.

    Etiam aliquam eros orci, eu malesuada ipsum commodo quis.

     
  • Ok here is it:
    def yourText = '''
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin congue tempus tempor. Donec pretium viverra eleifend.
    Aliquam et condimentum sem. Sed molestie nisl lectus, eget ultrices lorem tincidunt in. Morbi sed hendrerit dolor. Aliquam erat volutpat.
    Integer maximus ex tempus auctor elementum. Vivamus vel lacus eu ante maximus consequat. Vestibulum lacus eros, gravida in massa ut, malesuada ultricies quam.
    Suspendisse pharetra eros nec auctor posuere. Nunc sit amet dignissim eros. Suspendisse imperdiet tristique massa, id lacinia orci viverra id.
    Etiam aliquam eros orci, eu malesuada ipsum commodo quis.
    '''
    WebUI.setText(findTestObject('Page_CuraAppointment/txt_Comment'), yourText)
    Here is the screenshot: http://prntscr.com/fgv3t0


  • Hi,

    Was struggling with the same today to add next lines in a textarea. Ended up creating a custom keyword which changes '\n' from the input string to shift+enter keys too simulate the next line, hope this helps.

    The custom keyword:

    /**
    * Set the text of a textarea, next line with '\n'.
    * @param testObject Katalon test object.
    * @param text Text to add too the textarea.
    */
    @Keyword
    def SetTextArea(TestObject testObject, String text) {
    if(text.contains("\\n")){
    text = text.replace("\\n", Keys.chord(Keys.SHIFT, Keys.ENTER))
    }
    else{
    text = text.replace("\n", Keys.chord(Keys.SHIFT, Keys.ENTER))
    }

    WebUI.sendKeys(testObject, text)
    }

    Details about custom keywords: https://www.katalon.com/resources-center/tutorials/advanced/create-custom-keyword/
  • ok, so in the Input i put Variable and for value testObject? because i does not want to work

     

    edit. THe browser opens until that step but nothing happens http://i.imgur.com/NxvSo8E.png
  • @Francisc Lukacs said:
    The thing is, that this website will have text fields that will have up to 600.000 characters (that's the max i've seen so far) but mostly between 100's and 1000's, many of them having multiple lines. It would be nonsense for me to put a separator between every new line ( i want to use real data, not copy pasting 1000 words with separators between them)

    Come on dude this is free open source and not a paid one where you or your company can demand features and functions...

Sign In or Register to comment.