katalon-studio / katalon-recorder

Apache License 2.0
315 stars 140 forks source link

Robot Framework export formatter missing dependency and other issues #25

Closed reyelts closed 4 years ago

reyelts commented 5 years ago

We started playing around with the export for Robot Framework and found a number of issues. I spent some time over the past week reworking robot.js to get it to a point where the output RF script can successfully run unmodified:

1) The output script depends on a file seleniumLibrary.robot that is not included with Katalon Recorder. -- Based on a hint from the README, I found the missing file in the Robot-Framework-Formatter project. Instead of just copying the file into Katalon Recorder (which would be difficult for RF to use), I changed the code so it embeds the content directly into the output script.

2) The seleniumLibrary.robot implementation does not provide function for sendKeys or submit. (There are many others missing: these just came up first thing in our tests.) -- I added code to the output script that handles both. For sendKeys, I strip off the "KEY_" prefix of the key name and convert it to a constant on the way by... the Robot Framework implementation requires, for example, "ENTER" instead of "KEY_ENTER".

3) The seleniumLibrary.robot implementation asks for Robot Framework's Selenium2Library instead of the current SeleniumLibrary. -- I changed the new output script to ask for the current SeleniumLibrary.

4) The output script always specifies to use Firefox even if Chrome was used to generate it. -- I changed the formatter to query the running browser to look for and use "chrome" or "firefox". While it currently can't happen (because the extension is only available for Chrome and Firefox), I included an otherwise clause to default to "firefox" in the event the extension is enabled for another browser in the future.

5) The test case name in the output script is always "Test Case". -- I changed the code to find and use the test case name as defined in Katalon Recorder(if available).

6) The output script always demands to open www.katalon.com and then switches to the recorded website. While a nice ad for Katalon, this adds a lot of time to test runs. -- I changed the code to look at the first Selenium statement from Katalon Recorder. If it requests to open a browser, the output script launches directly to the website specified on that request. If not, it defaults to the original behavior of opening www.katalon.com first.

7) The output script does not provide for controlling the speed of test execution. -- I added a provision for Set Selenium Speed to be adjusted via a variable named SELSPEED. In the output script, the speed is set to 0 (no delay). When Robot Framework is launched, the user can specify --variable SELSPEED:n to tune to their needs.

I hope to submit a pull request for the above later today. (My first time submitting code through github... please be gentle.) Suggestions welcome.


Note: I did toy with the idea of directly mapping Selenium commands to Robot Framework commands. The current implementation does this:

   *** Test Cases ***
   My Test Case   
       submit  id=search_form_page

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

The test case line is an adaptation of the original Selenium line from Katalon Recorder... basically, the "|" characters are stripped out to make it look to Robot Framework like a regular keyword call. The last three lines are provided from seleniumLibrary.robot (now directly embedded). So at run time, Robot Framework sees the test case line as a call to "submit" and transfers control to the "submit" keyword/function who in turn launches RF/SeleniumLibrary's "Submit Form".

While this works, it is inefficient. First, it means all the possible mappings are defined ahead of time and are always interpreted by RF: even if they aren't used. Second, it means every step requires a call to the translate keyword/function, parsing of arguments, and another call to the real target keyword/function. The robot.js script could just as easily generate the translation directly, like this:

    *** Test Cases ***
    My Test Case
        # submit | id=search_form_page |
        Submit Form id=search_form_page

The first line is a comment reflecting the original that came from Katalon Recorder as-is. The second would be the RF equivalent as derived by the formatter... invoked directly instead of with all the overhead of the original. As a side effect, traces and logs from RF would be much simpler.

Like I said, I didn't implement this in the forthcoming pull request. It's just an optimization I'd like to consider in the future... and would like to hear opinions before investing the time.

reyelts commented 5 years ago

Opened pull request #26 for this issue.