<jupyter_start><jupyter_text>IPython MagicNot to leave the upstream out, you can bring Robot Framework into your IPython kernel. Note that you won't get much help from the Inspector or completion... yet!First, `reload_ext` the `irobotframework` IPython extension.<jupyter_code>%reload_ext irobotframework<jupyter_output><empty_output><jupyter_text>Now you can start cells with `%%robot` and get the same Robot outputs as from the `irobotframework` Kernel.<jupyter_code>%%robot
*** Tasks ***
This will Fail
    This is not a keyword<jupyter_output><empty_output><jupyter_text>FailThe above failed with a `RobotMagicError`. If you want to _show_ a failing test as part of your notebook narrative and continue execution, pass `--noraise`.<jupyter_code>%%robot --no-raise
*** Tasks ***
This will Fail
    This is not a keyword<jupyter_output><empty_output><jupyter_text>ReturnUseful, but what if you want to find out more? `--return` the test [results](https://github.com/robotframework/robotframework/blob/master/src/robot/result/executionresult.py)!<jupyter_code>%%robot --no-raise --return
*** Tasks ***
This will Fail
    This is not a keyword<jupyter_output><empty_output><jupyter_text>You can then pull the result off with `_`....<jupyter_code>results = _
results<jupyter_output><empty_output><jupyter_text>Which has lots of useful things, like statistics:<jupyter_code>vars(results.statistics.total.all)<jupyter_output><empty_output><jupyter_text>Assign Or, if you're going to do more work with the suite output, you can `--assign` it to a variable:<jupyter_code>%%robot --assign other_results
*** Tasks ***
This will Fail
    This is not a keyword
other_results.statistics.total.all.failed<jupyter_output><empty_output><jupyter_text>Jinja[Jinja](http://jinja.pocoo.org/docs/2.10/templates/) is the templating library of choice in the Jupyter ecosystem. It uses `{{ print_this }}` and `{% do_that %}{% end_that %}`, so it doesn't conflict with Robot syntax. If you have it installed in your environment (e.g. you installed `notebook` or `jupyterlab`), you can use the `--jinja` argument (which optionally accepts the name of a `dict`-like variable) to do string replacement of your Robot code:<jupyter_code>how_long = 1000
%%robot --jinja --no-raise
*** Variables ***
${tusks collected}  ${0}
${tusks needed}  ${65340285}
${hp}  ${10}

*** Tasks ***
Go Adventuring
{% for i in range(how_long) %}
    Fight a boar
{% endfor %}
    Bring tusks to townsperson

*** Keywords ***
Fight a Boar
    ${d12} =  Evaluate  random.randint(1, 12)  random
    Run Keyword If  ${d12} < 5  The Boar Hits You
    ...  ELSE IF  ${d12} > 8  Collect a Boar Tusk
    
Collect a Boar Tusk
    Set Global Variable  ${tusks collected}  ${tusks collected + 1}

Bring Tusks to Townsperson
    Should be Equal as Integers  ${tusks collected}  ${tusks needed}
    ...   msg=*HTML* <h1>You need ${tusks needed - ${tusks collected} / 1e6} more megatusks</h1>

The Boar Hits You
    Set Global Variable  ${hp}  ${hp-1}
    Should be True  ${hp}  msg=*HTML* <h1>You were defeated</h1><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11799027552674231, 'fraction_numerical': 0.011993517017828201, 'mean_word_length': 4.8007518796992485, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '246723', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1081, 'n_tokens_neox': 1037, 'n_words': 332, 'path': 'docs/Magic.ipynb', 'repo_name': 'bollwyvl/irobotframework', 'size': '3085'}