使用Robot Framework的Process lib,curl -c将不会创建cookie [英] Using Robot Framework's Process lib, curl -c will not create a cookie

查看:75
本文介绍了使用Robot Framework的Process lib,curl -c将不会创建cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Process lib,我创建了以下内容:

Using the Process lib, I have created the following:

*** Settings ***
Documentation

Library    Process
Library    OperatingSystem

*** Test Case ***
Test Case
    Start Sesh

*** Keyword ***
Start Sesh
    ${Authenticate}=    Run Process  curl  -c cookie.txt  -d j_username\=regression1%40att&j_password\=TCpass1234&submit\=Login  https://api.company.com/j_spring_security_check

在命令行上运行curl命令会在工作目录中生成一个名为cookie.txt的cookie.

Running the curl command on a command line produces a cookie titled cookie.txt in the working directory.

出于某种原因在Robot Framework中运行命令甚至都不会创建文本文件,更不用说在会话中填充文本文件了.

Running the command in Robot Framework for some reason will not even create the text file, let alone populate it with a session.

目标:我试图通过卷曲的方式在RF中创建cookie,就像在命令行场景中一样.

Goal: I am trying to get curl to create a cookie in RF the same way it would in a command line scenario.

编辑:我可能已经通过使用shell = True解决了该问题.保持发布状态

EDIT: I may have solved the issue by using shell=True. Stay posted

推荐答案

如果您想使用Robot Framework运行CURL,以下是答案:

先决条件:

  • 进程库
  • 适用于Windows的卷发
  • 在Windows中将Curl.exe设置为您的Path变量
  • 也知道我可以将其与REST API一起使用

代码:

*** Settings ***
Documentation

Library    Process

*** Variables ***
${COOKIE}            C:/sq_automation/cookie.txt

*** Keywords ***
Start API Session
    ${Authenticate}    Run Process    curl -i -c ${COOKIE} -d "j_username\=regression1%40att&j_password\=TCpass1234&submit\=Login https://api.website.com/j_spring_security_check"    shell=True    alias=Auth    cwd=C:/sq_automation
    Should Contain    ${Authenticate.stdout}    HTTP/1.1 302 Found
    ${result}    Get Process Result    Auth    rc=True    stdout=True    stderr=True

API POST
    ${Login}    Run Process    curl -i -b ${COOKIE} -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d "{\\"password\\":\\"${PASSWORD}\\",\\"username\\":\\"${USERID}\\"}" https://api.touchcommerce.com/engagementAPI/v1/agent/login?output\=json    shell=True    alias=Login    cwd=C:/sq_automation
    Should Contain    ${Login.stdout}    HTTP/1.1 200 OK
    ${result}    Get Process Result    Login    rc=True    stdout=True    stderr=True
    Get Registered ID    ${Login.stdout}

我只能使它与shell = True一起使用.编写curl命令时,必须在参数之间仅留一个空格,并且对于反斜杠和等号,必须使用适当的字符转义符.

I could only get this to work with shell=True. It is necessary that you write the curl command with only one space between arguments and the proper character escapes for backslashes, and equal signs.

这篇关于使用Robot Framework的Process lib,curl -c将不会创建cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆