katalon-studio / katalon-recorder

Apache License 2.0
315 stars 141 forks source link

Issue #25 Robot Framework export formatter missing dependency #26

Closed reyelts closed 5 years ago

reyelts commented 5 years ago

Resolve #25 .

I tested this with both Chrome and Firefox (both on Mac). The behavior is identical.

Sample output from old robot.js:

*** Settings ***
Suite Setup    Open Browser    https://www.katalon.com/    firefox
Suite Teardown    Close Browser
Resource    seleniumLibrary.robot

*** Variables ***
${undefined}    https://www.katalon.com/

*** Test Cases ***
Test Case
    open    https://duckduckgo.com/
    click    id=search_form_input_homepage
    type    id=search_form_input_homepage    this is a test
    submit    id=search_form_homepage

Sample output from new robot.js:

*** Settings ***
Library  SeleniumLibrary

*** Variables ***
${BROWSER}   chrome
${SELSPEED}  0.0s

*** Test Cases ***
TestDuck
    [Setup]  Run Keywords  Open Browser  https://duckduckgo.com/  ${BROWSER}
    ...              AND   Set Selenium Speed  ${SELSPEED}
    # open    https://duckduckgo.com/
    click    id=search_form_input_homepage
    type    id=search_form_input_homepage    this is a test
    submit    id=search_form_homepage
    [Teardown]  Close Browser

*** Keywords ***
open
    [Arguments]    ${element}
    Go To          ${element}

clickAndWait
    [Arguments]    ${element}
    Click Element  ${element}

click
    [Arguments]    ${element}
    Click Element  ${element}

sendKeys
    [Arguments]    ${element}    ${value}
    Press Keys     ${element}    ${value}

submit
    [Arguments]    ${element}
    Submit Form    ${element}

type
    [Arguments]    ${element}    ${value}
    Input Text     ${element}    ${value}

selectAndWait
    [Arguments]        ${element}  ${value}
    Select From List   ${element}  ${value}

select
    [Arguments]        ${element}  ${value}
    Select From List   ${element}  ${value}

verifyValue
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

verifyText
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

verifyElementPresent
    [Arguments]                  ${element}
    Page Should Contain Element  ${element}

verifyVisible
    [Arguments]                  ${element}
    Page Should Contain Element  ${element}

verifyTitle
    [Arguments]                  ${title}
    Title Should Be              ${title}

verifyTable
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

assertConfirmation
    [Arguments]                  ${value}
    Alert Should Be Present      ${value}

assertText
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

assertValue
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

assertElementPresent
    [Arguments]                  ${element}
    Page Should Contain Element  ${element}

assertVisible
    [Arguments]                  ${element}
    Page Should Contain Element  ${element}

assertTitle
    [Arguments]                  ${title}
    Title Should Be              ${title}

assertTable
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

waitForText
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

waitForValue
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

waitForElementPresent
    [Arguments]                  ${element}
    Page Should Contain Element  ${element}

waitForVisible
    [Arguments]                  ${element}
    Page Should Contain Element  ${element}

waitForTitle
    [Arguments]                  ${title}
    Title Should Be              ${title}

waitForTable
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

doubleClick
    [Arguments]           ${element}
    Double Click Element  ${element}

doubleClickAndWait
    [Arguments]           ${element}
    Double Click Element  ${element}

goBack
    Go Back

goBackAndWait
    Go Back

runScript
    [Arguments]         ${code}
    Execute Javascript  ${code}

runScriptAndWait
    [Arguments]         ${code}
    Execute Javascript  ${code}

setSpeed
    [Arguments]           ${value}
    Set Selenium Timeout  ${value}

setSpeedAndWait
    [Arguments]           ${value}
    Set Selenium Timeout  ${value}

verifyAlert
    [Arguments]              ${value}
    Alert Should Be Present  ${value}
reyelts commented 5 years ago

Is anybody out there?

alane019 commented 5 years ago

Yes.

On Wed, Aug 7, 2019, 12:05 PM Tony Reyelts notifications@github.com wrote:

Is anybody out there?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/katalon-studio/katalon-recorder/pull/26?email_source=notifications&email_token=ACNOD6VPQZLKMQKVRMPDX5DQDLXDVA5CNFSM4IGKF4C2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3Y42GY#issuecomment-519163163, or mute the thread https://github.com/notifications/unsubscribe-auth/ACNOD6S5J6IKNZOQXMKF3GLQDLXDVANCNFSM4IGKF4CQ .

reyelts commented 5 years ago

I guess I should have been more clear. I was hoping to learn whether my pull request would make it into the base in the foreseeable future. Anything I need to do differently to contribute?

alane019 commented 5 years ago

That's not something that I have access to do. Personally, I've been subscribed ever since I answered a question on how to use a particular feature for someone. Unfortunately I'm not sure how often the devs look at pull requests. Good luck!

On Thu, Aug 8, 2019, 6:33 PM Tony Reyelts notifications@github.com wrote:

I guess I should have been more clear. I was hoping to learn whether my pull request would make it into the base in the foreseeable future. Anything I need to do differently to contribute?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/katalon-studio/katalon-recorder/pull/26?email_source=notifications&email_token=ACNOD6TAPZWYNPYEQTZLZHDQDSNKPA5CNFSM4IGKF4C2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD35CVKY#issuecomment-519711403, or mute the thread https://github.com/notifications/unsubscribe-auth/ACNOD6V2TVMVYRGGQS3GSFDQDSNKPANCNFSM4IGKF4CQ .

devalex88 commented 5 years ago

Hi @reyelts,

Thank you so much for the PR. It looks good to me, however, there is a minor bug that I hope you can help us investigate. The test case is attached as robot-test.txt (please rename the file to robot-test.html and import it to KR).

Bug description: https://katalon-test.s3.amazonaws.com/demo-aut/dist/html/form.html is exported as https://katalon-test.s3.amazonaws.com/demo-aut/distxpath=/html/form.html.

open | https://katalon-test.s3.amazonaws.com/demo-aut/dist/html/form.html | 
# | This is a comment. | 
click | id=first-name | 
type | id=first-name | Alex
type | id=last-name | Smith
click | name=gender | 
click | id=dob | 
click | //tr[4]/td[3] | 
click | id=address | 
type | id=address | 123456 Wakanda
click | id=email | 
type | id=email | alex@wakanda.gov
click | id=password | 
type | id=password | secret
click | id=company | 
type | id=company | Dora
select | id=role | label=Manager
click | id=role | 
addSelection | id=expectation | label=Nice manager/leader
click | //select[@id='expectation']/option[2] | 
addSelection | id=expectation | label=Excellent colleagues
click | //select[@id='expectation']/option[3] | 
addSelection | id=expectation | label=Good teamwork
click | //select[@id='expectation']/option[4] | 
click | //input[@value=''] | 
click | xpath=(//input[@value=''])[2] | 
click | id=comment | 
type | id=comment | Added by Alex.
click | id=submit | 
*** Settings ***
Library  SeleniumLibrary

*** Variables ***
${BROWSER}   chrome
${SELSPEED}  0.0s

*** Test Cases ***
Common actions
    [Setup]  Run Keywords  Open Browser  https://katalon-test.s3.amazonaws.com/demo-aut/distxpath=/html/form.html  ${BROWSER}
    ...              AND   Set Selenium Speed  ${SELSPEED}
    # open    https://katalon-test.s3.amazonaws.com/demo-aut/distxpath=/html/form.html
    #    This is a comment.
    click    id=first-name
    type    id=first-name    Alex
    type    id=last-name    Smith
    click    name=gender
    click    id=dob
    click    xpath=//tr[4]/td[3]
    click    id=address
    type    id=address    123456 Wakanda
    click    id=email
    type    id=email    alex@wakanda.gov
    click    id=password
    type    id=password    secret
    click    id=company
    type    id=company    Dora
    select    id=role    Manager
    click    id=role
    addSelection    id=expectation    Nice manager/leader
    click    xpath=//select[@id='expectation']/option[2]
    addSelection    id=expectation    Excellent colleagues
    click    xpath=//select[@id='expectation']/option[3]
    addSelection    id=expectation    Good teamwork
    click    xpath=//select[@id='expectation']/option[4]
    click    xpath=//input[@value='']
    click    xpath=(//input[@value=''])[2]
    click    id=comment
    type    id=comment    Added by Alex.
    click    id=submit
    [Teardown]  Close Browser

*** Keywords ***
open
    [Arguments]    ${element}
    Go To          ${element}

clickAndWait
    [Arguments]    ${element}
    Click Element  ${element}

click
    [Arguments]    ${element}
    Click Element  ${element}

sendKeys
    [Arguments]    ${element}    ${value}
    Press Keys     ${element}    ${value}

submit
    [Arguments]    ${element}
    Submit Form    ${element}

type
    [Arguments]    ${element}    ${value}
    Input Text     ${element}    ${value}

selectAndWait
    [Arguments]        ${element}  ${value}
    Select From List   ${element}  ${value}

select
    [Arguments]        ${element}  ${value}
    Select From List   ${element}  ${value}

verifyValue
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

verifyText
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

verifyElementPresent
    [Arguments]                  ${element}
    Page Should Contain Element  ${element}

verifyVisible
    [Arguments]                  ${element}
    Page Should Contain Element  ${element}

verifyTitle
    [Arguments]                  ${title}
    Title Should Be              ${title}

verifyTable
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

assertConfirmation
    [Arguments]                  ${value}
    Alert Should Be Present      ${value}

assertText
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

assertValue
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

assertElementPresent
    [Arguments]                  ${element}
    Page Should Contain Element  ${element}

assertVisible
    [Arguments]                  ${element}
    Page Should Contain Element  ${element}

assertTitle
    [Arguments]                  ${title}
    Title Should Be              ${title}

assertTable
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

waitForText
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

waitForValue
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

waitForElementPresent
    [Arguments]                  ${element}
    Page Should Contain Element  ${element}

waitForVisible
    [Arguments]                  ${element}
    Page Should Contain Element  ${element}

waitForTitle
    [Arguments]                  ${title}
    Title Should Be              ${title}

waitForTable
    [Arguments]                  ${element}  ${value}
    Element Should Contain       ${element}  ${value}

doubleClick
    [Arguments]           ${element}
    Double Click Element  ${element}

doubleClickAndWait
    [Arguments]           ${element}
    Double Click Element  ${element}

goBack
    Go Back

goBackAndWait
    Go Back

runScript
    [Arguments]         ${code}
    Execute Javascript  ${code}

runScriptAndWait
    [Arguments]         ${code}
    Execute Javascript  ${code}

setSpeed
    [Arguments]           ${value}
    Set Selenium Timeout  ${value}

setSpeedAndWait
    [Arguments]           ${value}
    Set Selenium Timeout  ${value}

verifyAlert
    [Arguments]              ${value}
    Alert Should Be Present  ${value}

robot-test.txt

reyelts commented 5 years ago

Hi @devalex88 , I've researched the symptom you reported. My pull request is faithful to the original code base with which I started. Here's a snippet of the export result using the original. It does the same thing:

*** Settings ***
Suite Setup    Open Browser    https://www.katalon.com/    firefox
Suite Teardown    Close Browser
Resource    seleniumLibrary.robot

*** Variables ***
${undefined}    https://www.katalon.com/

*** Test Cases ***
Test Case
    open    https://katalon-test.s3.amazonaws.com/demo-aut/distxpath=/html/form.html
    #    This is a comment.
    click    id=first-name
    type    id=first-name    Alex
    type    id=last-name    Smith

The symptom is caused by a function named filterForRemoteControl(). It is some sort of pre-processor that modifies the commands coming in from Katalon Recorder. It makes the following transformations:

  1. It converts incoming command strings from the form command | target | value to command target value. (This seems a waste. It earlier converts them from the object form to the one with |. It would be smarter to not do that at all rather than add and then remove them.)
  2. It removes any instance of the string label=.
  3. It changes the first instance of // (two slashes preceded by a space) to xpath=//.
  4. It changes the first instance of /html to xpath=/html.
  5. My pull request added code to convert ${KEY_keyname} to keyname so commands like Press Keys work on the Robot Framework side.

Transformation #4 above is causing your test case to fail.


There are a couple of ways to fix this:

If we remove #4, I would be inclined to change the code to be smarter about the others:

I'm happy to code/test a pull request to solve this problem. My vote would be to do the second/longer solution of removing #4 and tuning the rest to be smarter. It is more work, but will fix more than just the one problem. For example, the old approach is broken if the open URL happens to contain the string label=. It is also broken if a value contains |.

Since my original pull request did not cause the symptom, I would prefer that you:

  1. Re-commit my original pull request #26 or back out the #28 that removed it.
  2. Create an issue specifically for this pre-existing symptom so it is documented properly. Then I can tie the new pull request back to that issue.

Let me know how you would like to proceed.

devalex88 commented 5 years ago

I'm sorry I had not checked the original version. The new changes will be released today. Thank you again for this contribution.

reyelts commented 5 years ago

Thanks @devalex88 ! Do you have an opinion on my two suggested paths for fixing the problem you reported with xpath being added to the URL? I'm thinking of starting a new PR to fix that.

I've given it a little more thought. I would do one thing differently than the original proposal. Instead of removing #4 (the code that adds xpath to /html), I would change the code to behave like my proposal for #3: if command.target starts with "/html", then add "xpath=" to it.

devalex88 commented 4 years ago

Thank you @reyelts. I've fixed the issue using your elegant #3 suggestion.