机器人框架拆分字符串并放入表格excel

时间:2017-11-24 09:03:54

标签: automated-tests robotframework

我想要分割Transaction ID:211444,我想只获取值= ' 211444' 并将其放入表格excel? 有人请帮忙

2 个答案:

答案 0 :(得分:1)

使用OperatingSystem.py和String.py库:

${string} =    Convert to String    Transaction ID:211444
${id} =    Fetch From Right    ${string}    ID:
append to file    ids.csv    ID:${id}\n   encoding=UTF-8

答案 1 :(得分:0)

这可能对您有用。

您可能确定在python包中安装了 xlsxwriter 。 别的吗

pip install xlsxwriter

下面是robotfile内容,它将把字母数字字符串传递给用python

编写的库

<强> sample.robot

*** Settings ***
#test.py is name of python file in which code to write in excel is written

Library  test.py

*** Variables ***
#This is sample alphanumeric value passed to python function

${test}    pankaj:12232
*** Test Cases ***
Test
    value is
*** Keywords ***
value is

#excel_numeric is function written in python to remove strings and write to excel

    excel_numeric     ${test}
    #log to console    ${compare}

Python文件 的 test.py

import xlsxwriter
def excel_numeric(arg1):
    import re
    #this will only provide numeric value from strings
    arg2=re.findall(r'\d+',arg1)
    workbook = xlsxwriter.Workbook(r'D:\dummy.xlsx')
    worksheet = workbook.add_worksheet()
    for item in arg2:
        print item
        #write takes three arguments,row,column and value
        worksheet.write(0,0,item)
    workbook.close()

输出

12232 - Written in excelfile

注意 确保将robot和python文件放在同一目录中