RF


官網網址:http://robotframework.org/robotframework/#standard-libraries

https://blog.csdn.net/whackw/article/details/48804639

編碼問題:https://blog.csdn.net/m0_37615390/article/details/80798105

https://blog.csdn.net/Allan_shore_ma/article/details/65441853?locationNum=8&fps=1

 https://blog.csdn.net/Allan_shore_ma/article/details/65441853?locationNum=10&fps=1

 

 

selenium2library:https://www.cnblogs.com/hopchee/p/7922190.html

# BuiltIn

> 包含一些常用的關鍵字,能自動加載到內存。
>
> A. 各種數據類型,不同進制間的轉換 ( Convert To Integer , Convert To Hex )
> B. 各類驗證 ( Should Be Equal )
> c. 變量設置 ( Set Variable )
> d. 關鍵字運行設置 ( Run Keyword If )
> e. 流程控制類 ( exit for loop if )
> f. 各類數據處理類 ( 日期處理,隨機數,中文,正則表達式:evaluate )
> g. 其他類 ( log sleep )

 

## Call Method

> 參數:[ object | method_name | *args | **kwargs ]
>
> 使用參數args調用對象object的方法method_name。
>
> 方法可能的返回值可以賦值給一個變量。
>
> 當找不到方法或者方法產生異常時,Keyword會失敗。

| Call Method | ${hashtable} | put | myname | myvalue |
| :----------------- | ------------ | ------------ | --------------- | ------- |
| ${isempty} = | Call Method | ${hashtable} | isEmpty | |
| Should Not Be True | ${isempty} | | | |
| ${value} = | Call Method | ${hashtable} | get | myname |
| Should Be Equal | ${value} | myvalue | | |
| Call Method | ${object} | kwargs | name=value | foo=bar |
| Call Method | ${object} | positional | escaped\=equals | |

## Catenate*

>參數:[ *items ]
>
>連接給定參數,返回字符串。
>
>默認用空格連接參數項目,如果第一個參數為'SEPARATOR=<sep>',則使用”sep”來連接。

| ${str1} = | Catenate | Hello | world | |
| --------- | -------- | ------------- | ----- | ----- |
| ${str2} = | Catenate | SEPARATOR=--- | Hello | world |

```
${str1} = 'Hello world'
${str2} = 'Hello---world'
```

## Comment***

>參數:[ *messages ]
>
>注釋,comment之后的同一行所有信息無效。

## Continue*

### Continue For Loop If

>參數:[ condition ]
>
>如果條件生效,則跳過此輪循環。

| :FOR | ${var} | IN | @{VALUES} | |
| ---- | -------------------- | ---------------------- | --------- | ---- |
| | Continue For Loop If | '${var}' == 'CONTINUE' | | |
| | Do Something | ${var} | | |

```
有列表@{VALUES},循環遍歷,如果'${var}' != 'CONTINUE',則執行do something,然后繼續遍歷下一個元素。如果遍歷到某個元素'${var}' == 'CONTINUE',則此輪循環結束,do something語句不執行,直接做下一輪循環。(FOR語句不結束)
```

### Continue For Loop

>參數:[ ]
>
>強制性跳過此輪循環

| :FOR | ${var} | IN | @{VALUES} | |
| ---- | -------------- | ---------------------- | ----------------- | ---- |
| | Run Keyword If | '${var}' == 'CONTINUE' | Continue For Loop | |
| | Do Something | ${var} | | |

```
跟Continue For Loop If起到的效果一樣,兩種不一樣的寫法,可以100%替代。只不過Continue For Loop If自帶判斷,Continue For Loop需要用run keyword if 去判斷,根據判斷結果運不運行。
```

## Convert To

### Convert To Binary

>參數:[ item | base=None | prefix=None | length=None ]
>
>如果添加了base參數,則先內部使用[Convert To Integer](http://translate.googleusercontent.com/translate_c?hl=zh-CN&ie=UTF8&prev=_t&rurl=translate.google.com.hk&sl=en&tl=zh-CN&u=http://robotframework.googlecode.com/hg/doc/libraries/BuiltIn.html%3Fr%3D2.6.3&usg=ALkJrhgMIkOCC2JIdCaKYdybQeMJs4RzxQ#Convert%20To%20Integer)轉換為整數,然后再轉換為二進制數字,以字符串的形式顯示,比如”1011“。
>
>返回值可以包含可選的前綴(prefix)和最小長度(length不包含前綴和負號等)。如果返回值比要求的長度短,則使用0填充。

| ${result1} = | Convert To Binary | 10 | | |
| ------------ | ----------------- | ---- | -------- | --------- |
| ${result2} = | Convert To Binary | F | base=16 | prefix=0b |
| ${result3} = | Convert To Binary | -2 | prefix=B | length=4 |

```
${result1} = 1010
${result2} = 0b1111
${result3} = -B0010
```

 

### Convert To Boolean***

>參數:[ item ]
>
>轉換參數為布爾值true或false。
>
>如果參數是字符串'True'(不區分大小寫)就返回真,為'False'就返回假;其他情況調用Python的'bool'的方法來判斷。請參閱[http://docs.python.org/lib/truth.html](http://translate.googleusercontent.com/translate_c?hl=zh-CN&ie=UTF8&prev=_t&rurl=translate.google.com.hk&sl=en&tl=zh-CN&u=http://docs.python.org/lib/truth.html&usg=ALkJrhi7y1ZLKUXpm4Kv4rMpBmAD3CnfUA) 。
>
>

### Convert To Bytes

>參數:[ input | input_type=text ]
>
>這個關鍵字跟python2的編碼格式高度相關,很難使用到,如果真的要使用,具體看F5文檔,很詳細了。

 

### Convert To Hex

>參數:[ item | base=None | prefix=None | length=None | lowercase=False ]
>
>轉換參數為十六進制字符串。
>
>如果添加了base參數,則先內部使用[Convert To Integer](http://translate.googleusercontent.com/translate_c?hl=zh-CN&ie=UTF8&prev=_t&rurl=translate.google.com.hk&sl=en&tl=zh-CN&u=http://robotframework.googlecode.com/hg/doc/libraries/BuiltIn.html%3Fr%3D2.6.3&usg=ALkJrhgMIkOCC2JIdCaKYdybQeMJs4RzxQ#Convert%20To%20Integer)轉換為整數,然后再轉換為十六進制數字,以字符串的形式顯示,比如'FF0A'。
>
>返回值可以包含可選的前綴和最小長度(不包含前綴和負號等)。如果返回值比要求的長度短,則使用0填充。
>
>默認返回大寫字符串,lowercase參數會轉換值為小寫(不包含前綴)。

| ${result1} = | Convert To Hex | 255 | | |
| ------------ | -------------- | ---- | --------- | ------------- |
| ${result2} = | Convert To Hex | -10 | prefix=0x | length=2 |
| ${result3} = | Convert To Hex | 255 | prefix=X | lowercase=yes |

```
${result1} = FF
${result2} = -0x0A
${result3} = Xff
```

### Convert To Integer

>參數:[ item | base=None ]
>
>轉換參數為整數。
>
>如果參數是字符串,則默認轉為十進制整數。使用其他進制可以用base指定或者添加前綴,比如0b表示2進制,0o表示8進制,0x表示16進制。前綴只有當無base參數才可以添加,前綴的前面還可以添加加減等符號。
>
>語法不區分大小寫並忽略空格

| ${result} = | Convert To Interger | 100 | | # Result is 100 |
| ----------- | ------------------- | ------ | ---- | ----------------- |
| ${result} = | Convert To Interger | FF AA | 16 | # Result is 65450 |
| ${result} = | Convert To Interger | 100 | 8 | # Result is 64 |
| ${result} = | Convert To Interger | -100 | 2 | # Result is -4 |
| ${result} = | Convert To Interger | 0b100 | | # Result is 4 |
| ${result} = | Convert To Interger | -0x100 | | # Result is -256 |

### Convert To Number

>參數:[ item | precision=None ]
>
>轉換參數為浮點數。
>
>如果可選參數precision是正數或零,返回的四舍五入的值。負數則相當於修改-precision位數為0
>
>如果可選參數precision是負數,返回的四舍五入的值。

| ${result} = | Convert To Number | 42.512 | | # Result is 42.512 |
| ----------- | ----------------- | ------ | ---- | ------------------ |
| ${result} = | Convert To Number | 42.512 | 1 | # Result is 42.5 |
| ${result} = | Convert To Number | 42.512 | 0 | # Result is 43.0 |
| ${result} = | Convert To Number | 42.512 | -1 | # Result is 40.0 |

### Convert To Octal

>參數:[ item | base=None | prefix=None | length=None ]
>
>轉換參數為八進制字符串。
>
>如果添加了base參數,則先內部使用[Convert To Integer](http://translate.googleusercontent.com/translate_c?hl=zh-CN&ie=UTF8&prev=_t&rurl=translate.google.com.hk&sl=en&tl=zh-CN&u=http://robotframework.googlecode.com/hg/doc/libraries/BuiltIn.html%3Fr%3D2.6.3&usg=ALkJrhgMIkOCC2JIdCaKYdybQeMJs4RzxQ#Convert%20To%20Integer)轉換為整數,然后再轉換為八進制數字,以字符串的形式顯示,比如'775''。
>
>返回值可以包含可選的前綴和最小長度(不包含前綴和負號等)。如果返回值比要求的長度短,則使用0填充。
>
>默認返回大寫字符串,lowercase參數會轉換值為小寫(不包含前綴)。

| ${result} = | Convert To Octal | 10 | | | # Result is 12 |
| ----------- | ---------------- | ---- | ---------- | -------- | ------------------- |
| ${result} = | Convert To Octal | -F | base=16 | prefix=0 | # Result is -017 |
| ${result} = | Convert To Octal | 16 | prefix=oct | length=4 | # Result is oct0020 |

### Convert To String

>參數:[ item ]
>
>轉換參數為Unicode字符串。
>
>針對Python對象使用“__unicode__'或'__str__’方法。

## Create***

### Create Dictionary

>參數:[ *items ]
>
>根據給定的 items 創建和返回字典。
>
>通常使用與變量表中創建的 &{dictionary} 變量相同的方式給出 鍵=值 語法。鍵和值都可以包含變量,鍵中可能的等號可以通過反斜杠(如escaped\\=key=value)進行轉義。也可以通過簡單地使用類似 \${DICT} 來從現有字典中獲取items。
>
>另外,可以指定項目,以便分別給出鍵和值。這個和 key=value 語法甚至可以組合,但是單獨給定的 items 必須放在第一個。
>
>如果使用相同的密鑰多次,則最后一個值優先。返回的字典是有序的,並且具有字符串作為鍵的值也可以使用方便的點訪問語法(如${..key})來訪問。

| &{dict} = | Create Dictionary | key=value | foo=bar | | | # key=value syntax |
| --------------- | ----------------------------------------------- | --------- | ------- | ------- | ---- | ------------------------ |
| Should Be True | ${dict} == {'key': 'value', 'foo': 'bar'} | | | | | |
| &{dict2} = | Create Dictionary | key | value | foo | bar | # separate key and value |
| Should Be Equal | ${dict} | ${dict2} | | | | |
| &{dict} = | Create Dictionary | ${1}=${2} | &{dict} | foo=new | | # using variables |
| Should Be True | ${dict} == {1: 2, 'key': 'value', 'foo': 'new'} | | | | | |
| Should Be Equal | ${dict.key} | value | | | | # dot-access |

### Create List

>參數:[ *items ]
>
>根據指定參數創建列表。返回的列表都用來給 ${scalar} 和 @{list} 變量賦值。

| @{list} = | Create List | a | b | c |
| ----------- | ----------- | ---- | ---- | ---- |
| ${scalar} = | Create List | a | b | c |
| ${ints} = | Create List | ${1} | ${2} | ${3} |

## Evaluate***

>參數:[ expression | modules=None | namespace=None ]
>
>用Python計算表達式並返回結果。
>
>modules參數可用於導入python模塊,可用逗號分隔符分開多個模塊。
>
>namespace參數可用於將自定義的評估命名空間作為字典傳遞。可能的模塊被添加到這個命名空間中。這是RF框架2.8中的一個新特性。

 

https://www.cnblogs.com/yrxns/p/6676582.html  時間模塊


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM