Francisc Lukacs
Katalon Apprentice
05/24/2017

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.

Upvote
Quote

Comments

  • Marek Melocik
    Katalon Ambassador
    05/24/2017
    Hello, try to add a line separators into a single setText method.
    WebUI.setText(testObject, "first line\nsecondline\nthird line")
    Upvote
    Quote
  • Francisc Lukacs
    Katalon Apprentice
    05/24/2017
    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)
    Upvote
    Quote
  • Marek Melocik
    Katalon Ambassador
    05/24/2017
    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?
    Upvote
    Quote
  • duyluong
    Katalon Apprentice
    05/24/2017
    Please try this

    Eg:

    def yourText = '''\

    Your text here

    '''

    Thanks.
    Upvote
    Quote
  • Francisc Lukacs
    Katalon Apprentice
    05/26/2017
    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.

     

     
    Upvote
    Quote
  • Francisc Lukacs
    Katalon Apprentice
    05/26/2017
    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.
    Upvote
    Quote
  • Vinh Nguyen
    Katalon Expert
    05/26/2017
    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
    Upvote
    Quote
  • Francisc Lukacs
    Katalon Apprentice
    05/26/2017
    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
    Upvote
    Quote
  • Francisc Lukacs
    Katalon Apprentice
    06/07/2017
    Hello. So how do i add this? keyword? could you please attach a pritnscreen?
    Upvote
    Quote
  • Vinh Nguyen
    Katalon Expert
    06/07/2017
    Do you have a sample text so that I can try and give you the screenshot?

    Thanks
    Upvote
    Quote
  • Francisc Lukacs
    Katalon Apprentice
    06/07/2017
    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.

     
    Upvote
    Quote
  • Vinh Nguyen
    Katalon Expert
    06/07/2017
    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
    Upvote
    Quote
  • robin
    Katalon Apprentice
    06/22/2017


    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/
    Upvote
    Quote
  • Francisc Lukacs
    Katalon Apprentice
    06/28/2017
    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
    Upvote
    Quote
  • Dhananjay
    Katalon Apprentice
    10/17/2017

    @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...

    Upvote
    Quote
  • Joseph
    Katalon Apprentice
    03/06/2018
    Hello,

    1. Put the multi-line text into an Excel file.
    2. Import the Excel file into Data Files.
    3. On your SetText step, the Value Type column should be "Test Data Value". Modify the "Value" column to reflect the correct row/column from the Excel.

    See: https://docs.katalon.com/display/KD/Manage+Test+Data
    Upvote
    Quote
Sign In or Register to comment.