PageSourceSearch

https://docs.robotframework.org/assets/js/dbd0cc4b.b71d0aeb.js

js robotframework.org collected 2026-10-01 11:45:45 UTC 13,380 bytes, 2 lines download raw bytes

1"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([["1362"],{1819(e,t,n){n.r(t),n.d(t,{metadata:()=>r,default:()=>g,frontMatter:()=>l,contentTitle:()=>d,toc:()=>u,assets:()=>c});var r=JSON.parse('{"id":"getting_started/how_to_write_rf","title":"Writing Your First Code","description":"The beginnings of the Robot Framework syntax","source":"@site/docs/getting_started/how_to_write_rf.mdx","sourceDirName":"getting_started","slug":"/getting_started/how_to_write_rf","permalink":"/docs/getting_started/how_to_write_rf","draft":false,"unlisted":false,"editUrl":"https://github.com/MarketSquare/robotframeworkguides/edit/main/website/docs/getting_started/how_to_write_rf.mdx","tags":[{"inline":true,"label":"beginner","permalink":"/docs/tags/beginner"},{"inline":true,"label":"syntax","permalink":"/docs/tags/syntax"}],"version":"current","sidebarPosition":4,"frontMatter":{"sidebar_position":4,"sidebar_label":"Writing Your First Code","title":"Writing Your First Code","description":"The beginnings of the Robot Framework syntax","tags":["beginner","syntax"]},"sidebar":"tutorialSidebar","previous":{"title":"Set up your IDE","permalink":"/docs/getting_started/ide"},"next":{"title":"Videos","permalink":"/docs/getting_started/videos"}}'),s=n(4848),a=n(8453);n(1113);var i=n(773),o=n(7250);let l={sidebar_position:4,sidebar_label:"Writing Your First Code",title:"Writing Your First Code",description:"The beginnings of the Robot Framework syntax",tags:["beginner","syntax"]},d="Writing Your First Code",c={},u=[{value:"File name",id:"file-name",level:2},{value:"Sections",id:"sections",level:2},{value:"Settings",id:"settings",level:3},{value:"Test Cases or Tasks",id:"test-cases-or-tasks",level:3},{value:"Indentation",id:"indentation",level:2},{value:"Everything together",id:"everything-together",level:2}];function h(e){let t={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",li:"li",ol:"ol",p:"p",pre:"pre",ul:"ul",...(0,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.header,{children:(0,s.jsx)(t.h1,{id:"writing-your-first-code",children:"Writing Your First Code"})}),"\n",(0,s.jsx)(t.p,{children:"Robot Framework is a versatile and powerful automation framework that uses plain text syntax. It is designed to be easy to read and write, making it accessible to both technical and non-technical users. In this guide, we\u2019ll cover the basics of Robot Framework syntax to get you started."}),"\n",(0,s.jsx)("br",{}),"\n",(0,s.jsx)(t.admonition,{type:"note",children:(0,s.jsx)(t.p,{children:"In this guide, we will primarily focus on testing, specifically Test Cases and Test Suites. The same principles also apply when discussing RPA Tasks."})}),"\n",(0,s.jsx)(t.h2,{id:"file-name",children:"File name"}),"\n",(0,s.jsx)(t.p,{children:"You can name your files anything you like, as long as they have the .robot extension. For example: 'MyFirstTest.robot'."}),"\n",(0,s.jsx)(t.h2,{id:"sections",children:"Sections"}),"\n",(0,s.jsx)(t.p,{children:"A Robot Framework test suite consists of multiple test cases organized within a single file. The basic structure of a test suite file includes the following sections:"}),"\n",(0,s.jsxs)(t.ol,{children:["\n",(0,s.jsx)(t.li,{children:"Settings"}),"\n",(0,s.jsx)(t.li,{children:"Test Cases"}),"\n"]}),"\n","\n",(0,s.jsx)(t.p,{children:"Although there are additional sections available, the Test Cases section is mandatory for running a test."}),"\n",(0,s.jsx)(t.h3,{id:"settings",children:"Settings"}),"\n",(0,s.jsx)(t.p,{children:"The Settings section is where you define the libraries, resource files, and other settings needed for your test suite."}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-robotframework",children:"*** Settings ***\nLibrary    String\n"})}),"\n",(0,s.jsx)(t.p,{children:"The libraries contain the keywords (functions/steps) that Robot Framework uses to execute tests. Each library includes documentation of the keywords it provides. To use these, importing the library is necessary."}),"\n",(0,s.jsx)(t.h3,{id:"test-cases-or-tasks",children:"Test Cases or Tasks"}),"\n",(0,s.jsx)(t.p,{children:"The Test Cases or Tasks section is where you define your individual test cases. Each test case/task is a sequence of keywords. These keywords determine the steps or actions that your test or task performs. There is no limit to the number of steps a test case can have, but there are good practices and it is good to create conventions with your co-workers to ensure readability."}),"\n",(0,s.jsxs)(i.A,{children:[(0,s.jsx)(o.A,{value:"tests",label:"Tests",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-robotframework",children:"*** Test Cases ***\nCreate A Random Str
1ing\n    Log To Console    We are going to generate a random string\n    Generate Random String  10\n    Log To Console    We finished generating a random string\n"})})}),(0,s.jsx)(o.A,{value:"tasks",label:"Tasks",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-robotframework",children:"*** Tasks ***\nCreate A Random String\n    Log To Console    We are going to generate a random string\n    Generate Random String  10\n    Log To Console    We finished generating a random string\n"})})})]}),"\n",(0,s.jsx)(t.h2,{id:"indentation",children:"Indentation"}),"\n",(0,s.jsx)(t.p,{children:"In the provided examples, you can see that Robot Framework code is separated by spaces. To correctly differentiate elements, Robot Framework requires at least two spaces. Here are a few examples based on the code we've seen so far:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-robotframework",children:"*** Settings ***\nLibrary    String\n"})}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:["The ",(0,s.jsx)(t.code,{children:"Library"})," keyword in the Settings section is unindented. This indicates that ",(0,s.jsx)(t.code,{children:"Library"})," is the setting being declared."]}),"\n",(0,s.jsxs)(t.li,{children:["Between ",(0,s.jsx)(t.code,{children:"Library"})," and ",(0,s.jsx)(t.code,{children:"String"}),", there are several spaces. This indicates that ",(0,s.jsx)(t.code,{children:"String"})," is the name of the library needed for our tests."]}),"\n"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-robotframework",children:"*** Test Cases ***\nCreate A Random String\n    Log To Console    We are going to generate a random string\n    Generate Random String    10\n    Log To Console    We finished generating a random string\n"})}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"Create A Random String"})," in the Test Cases section is unindented, indicating that it is a test case name."]}),"\n",(0,s.jsxs)(t.li,{children:["The lines below ",(0,s.jsx)(t.code,{children:"Create A Random String"})," are indented, showing that these are keywords used in the test case."]}),"\n",(0,s.jsxs)(t.li,{children:["Several spaces between ",(0,s.jsx)(t.code,{children:"Generate Random String"})," and ",(0,s.jsx)(t.code,{children:"10"})," indicate that ",(0,s.jsx)(t.code,{children:"10"})," is an argument for the keyword, specifying that our random string will be 10 characters long."]}),"\n",(0,s.jsxs)(t.li,{children:["The ",(0,s.jsx)(t.code,{children:"Log To Console"})," keywords are followed by a few spaces and a sentence. The spaces ensure that the following sentence is the text we want to log to our console."]}),"\n"]}),"\n",(0,s.jsxs)(t.p,{children:["You can see that spacing and indentation are extremely important in Robot Framework. They are necessary to distinguish between a keyword and its arguments, as well as to differentiate between test names and the keywords within the tests. Remember, Robot Framework needs at least two spaces to correctly differentiate elements. More spaces are also allowed. For more details on spacing conventions, refer to the ",(0,s.jsx)(t.a,{href:"/docs/style_guide#horizontal-spacing",children:"Style Guide"}),"."]}),"\n",(0,s.jsx)(t.h2,{id:"everything-together",children:"Everything together"}),"\n",(0,s.jsx)("iframe",{src:"https://robotframework.surge.sh/embed/?code-gh-url=https://github.com/MarketSquare/robotframeworkguides/tree/main/code-examples/my_first_test",width:"100%",height:"600"}),"\n"]})}function g(e={}){let{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},7250(e,t,n){n.d(t,{A:()=>o});var r=n(4848);n(6540);var s=n(8215),a=n(7663);function i({children:e,className:t,hidden:n}){return(0,r.jsx)("div",{role:"tabpanel",className:(0,s.A)("tabItem_Ymn6",t),hidden:n,children:e})}function o({children:e,className:t,value:n}){let{selectedValue:s,lazy:l}=(0,a.uc)(),d=n===s;return!d&&l?null:(0,r.jsx)(i,{className:t,hidden:!d,children:e})}},773(e,t,n){n.d(t,{A:()=>h});var r=n(4848);n(6540);var s=n(8215),a=n(8287),i=n(7663),o=n(8584),l=n(9863);function d({className:e}){let{selectedValue:t,selectValue:n,tabValues:a,block:l}=(0,i.uc)(),c=[],{blockElementScrollPositionUntilNextRender:u}
1=(0,o.a_)(),h=e=>{let r=e.currentTarget,s=a[c.indexOf(r)].value;s!==t&&(u(r),n(s))},g=e=>{let t=null;switch(e.key){case"Enter":h(e);break;case"ArrowRight":{let n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{let n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1]}}t?.focus()};return(0,r.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.A)("tabs",{"tabs--block":l},e),children:a.map(({value:e,label:n,attributes:a})=>(0,r.jsx)("li",{role:"tab",tabIndex:t===e?0:-1,"aria-selected":t===e,ref:e=>{c.push(e)},onKeyDown:g,onClick:h,...a,className:(0,s.A)("tabs__item","tabItem_LNqP",a?.className,{"tabs__item--active":t===e}),children:n??e},e))})}function c({children:e}){return(0,r.jsx)("div",{className:"margin-top--md",children:e})}function u({className:e,children:t}){return(0,r.jsxs)("div",{className:(0,s.A)(a.G.tabs.container,"tabs-container","tabList__CuJ"),children:[(0,r.jsx)(d,{className:e}),(0,r.jsx)(c,{children:t})]})}function h(e){let t=(0,l.A)(),n=(0,i.OC)(e);return(0,r.jsx)(i.O_,{value:n,children:(0,r.jsx)(u,{className:e.className,children:(0,i.vT)(e.children)})},String(t))}},7663(e,t,n){n.d(t,{OC:()=>h,O_:()=>f,uc:()=>m,vT:()=>c});var r=n(4848),s=n(6540),a=n(6347),i=n(9989),o=n(6629),l=n(618),d=n(1367);function c(e){return s.Children.toArray(e).filter(e=>"\n"!==e)}function u({value:e,tabValues:t}){return t.some(t=>t.value===e)}function h(e){let t,{defaultValue:n,queryString:r=!1,groupId:c}=e,h=function(e){let{values:t,children:n}=e;return(0,s.useMemo)(()=>{let e=t??s.Children.toArray(n).flatMap(e=>{if(!e)return[];if((0,s.isValidElement)(e)&&function(e){let{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return[e];let t="string"==typeof e.type?e.type:e.type.name;throw Error(`Docusaurus error: Bad <Tabs> child <${t}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.
2If you do not want to pass on a "value" prop to the direct children of <Tabs>, you can also pass an explicit <Tabs values={...}> prop.`)}).map(({props:{value:e,label:t,attributes:n,default:r}})=>({value:e,label:t,attributes:n,default:r})),r=(0,l.XI)(e,(e,t)=>e.value===t.value);if(r.length>0)throw Error(`Docusaurus error: Duplicate values "${r.map(e=>`'${e.value}'`).join(", ")}" found in <Tabs>. Every value needs to be unique.`);return e},[t,n])}(e),[g,m]=(0,s.useState)(()=>(function({defaultValue:e,tabValues:t}){if(0===t.length)throw Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(e){if(!u({value:e,tabValues:t}))throw Error(`Docusaurus error: The <Tabs> has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${t.map(e=>e.value).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}let n=t.find(e=>e.default)??t[0];if(!n)throw Error("Unexpected error: 0 tabValues");return n.value})({defaultValue:n,tabValues:h})),[f,b]=function({queryString:e=!1,groupId:t}){let n=(0,a.W6)(),r=function({queryString:e=!1,groupId:t}){if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!t)throw Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:e,groupId:t});return[(0,o.aZ)(r),(0,s.useCallback)(e=>{if(!r)return;let t=new URLSearchParams(n.location.search);t.set(r,e),n.replace({...n.location,search:t.toString()})},[r,n])]}({queryString:r,groupId:c}),[p,x]=function({groupId:e}){let t=e?`docusaurus.tab.${e}`:null,[n,r]=(0,d.Dv)(t);return[n,(0,s.useCallback)(e=>{t&&r.set(e)},[t,r])]}({groupId:c}),w=u({value:t=f??p,tabValues:h})?t:null;return(0,i.A)(()=>{w&&m(w)},[w]),{selectedValue:g,selectValue:(0,s.useCallback)(e=>{if(!u({value:e,tabValues:h}))throw Error(`Can't select invalid tab value=${e}`);m(e),b(e),x(e)},[b,x,h]),tabValues:h,lazy:e.lazy??!1,block:e.block??!1}}let g=(0,s.createContext)(null);function m(){let e=s.useContext(g);if(!e)throw Error("useTabsContext() must be used within a Tabs component");return e}function f(e){return(0,r.jsx)(g.Provider,{value:e.value,children:e.children})}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.