Giter Club home page Giter Club logo

Comments (4)

kkotenko avatar kkotenko commented on July 18, 2024

Would your scenario be solved by any of these?

  1. Create a resource file with arguments embedded in the keyword name, load said resource file and overwrite the variable by whatever you are generating dynamically

  2. Another approach would be to write your own keyword library, and overwrite the keyword name to use embedded arguments like so.

If not, could you say why these don't help?

from robotframework.

Tattoo avatar Tattoo commented on July 18, 2024

@kkotenko ,

I don't even need embedded arguments, I can just add my keywords to a resource file or a library:

# res.resource
*** Keywords ***
Example user keyword
    [Arguments]    ${arg}
    Pass execution    msg
# gen.py
from robot.api import TestSuite

for index in range(10):
    suite = TestSuite('Example Suite')
    suite.resource.imports.resource('res.resource')
    test = suite.tests.create('Example Test')
    kw = test.body.create_keyword('Example User Keyword', args=['my arg'])

    suite.run(output=f'output-{index}.xml')

But the point here is that this is cumbersome, compared to doing this directly from API.

from robotframework.

DimonLavron avatar DimonLavron commented on July 18, 2024

@Tattoo hi!

First of all - thank you for this issue. I started using robot framework recently, especially using programmatic API approach, so it helped me with a better understanding of programmatic API overall.

From my experience so far, I found out that all user keywords related to suite are stored in suite.resource.keywords, so you can easily add your user keywords there, for example:

from robot.api import TestSuite
from robot.running import UserKeyword

for index in range(10):
    suite = TestSuite('Example Suite')
    user_keyword = UserKeyword('Example User Keyword', args=('${arg}',))
    user_keyword.body.create_keyword('Pass Execution', args=('msg',))
    suite.resource.keywords.append(user_keyword)
    test = suite.tests.create('Example Test')
    test.body.create_keyword('Example User Keyword', args=('my arg',))

    suite.run(output=f'output-{index}.xml')

or you can pass your user keyword as dict:

from robot.api import TestSuite

for index in range(10):
    suite = TestSuite('Example Suite')
    suite.resource.keywords.append({
        "name": 'Example User Keyword',
        "args": ('${arg}',),
        "body": [
            {
                "name": 'Pass Execution',
                "args": ('msg',),
            },
        ],
    })
    test = suite.tests.create('Example Test')
    test.body.create_keyword('Example User Keyword', args=('my arg',))

    suite.run(output=f'output-{index}.xml')

I hope that I understand you correctly and it'll be helpful for you. Let me know if I misunderstand you, maybe I can find another solution that suits better for your needs!

from robotframework.

pekkaklarck avatar pekkaklarck commented on July 18, 2024

It is true that it isn't currently possible to define a higher level keyword with child keywords in the execution model. Basically a keyword in the execution model represents a keyword call with name and arguments. The keyword to actually run is resolved during execution and can either be a user keyword with child keywords or a library keyword.

Being able to define higher level keywords directly would be convenient in some cases. In addition to making it easier to programmatically create tests with suitable abstraction levels, it would make it easier for library keywords and listeners to create keywords with child keywords. We already have some other related enhancements initially planned to be done in RF 8, so I add this issue to its initial scope as well.

from robotframework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.