问题
Token&{head}=Create Dictionary Content-Type=application/x-www-form-urlencoded
Create Client Oauth2 Session temp token_url=https://websec-qa.cable.comcast.com/as/token.oauth2 tenant_id=customerequipmentqa tenant_secret=ac975251ba4349acbb962955876ec404 base_url=https://ce-service-qa.u1.app.cloud.comcast.net/xnet/ced/1.0/messages headers=&{head} verify=${True}
I am getting below error:
MissingSchema: Invalid URL 'None': No schema supplied
Perhaps you meant http://None?
回答1:
Check Webservice
${token_string}= Set Variable Bearer
Create Session webservice ${BASE_TOKEN_URL} verify=${True}
${data}= Create Dictionary token_name=customerequipment grant_type=client_credentials client_id=customerequipmentqa client_secret=ac975251ba4349acbb962955876ec404 scope=xnet:customerequipment
${headers}= Create Dictionary Content-Type=application/x-www-form-urlencoded
${resp}= Post Request webservice /as/token.oauth2 data=${data} headers=${headers}
Should Be Equal As Strings ${resp.status_code} 200
${token}= evaluate $resp.json().get("access_token")
${stripped_token}= Strip String ${token}
${token_string}= Catenate ${token_string} ${stripped_token}
[Return] ${token_string}
回答2:
In general it is best to provide a complete example, that also includes the specific libraries that are loaded. In this case a quick search on the keyword revealed that it's most likely the Extended Requests Library. With a few minor alterations I get a different error message that should be correct.
*** Settings ***
Library ExtendedRequestsLibrary
*** Test Cases ***
TC
#Token
&{head}= Create Dictionary Content-Type=application/x-www-form-urlencoded
Create Client Oauth2 Session
... label=temp
... token_url=https://websec-qa.cable.comcast.com/as/token.oauth2
... tenant_id=customerequipmentqa
... tenant_secret=ac975251ba4349acbb962955876ec404
... base_url=https://ce-service-qa.u1.app.cloud.comcast.net/xnet/ced/1.0/messages
... headers=${head}
... verify=${True}
Results in
Starting test: oAuth.Question2.TC 20180618 19:40:27.794 : INFO : &{head} = { Content-Type=application/x-www-form-urlencoded } 20180618 19:40:48.820 : FAIL : ConnectionError: ('Connection aborted.', error(10054, 'An existing connection was forcibly closed by the remote host')) Ending test: oAuth.Question2.TC
回答3:
So below is my code, however, I am getting 400!= 200
*** Keywords ***
Generate Token
${token_string}= Set Variable Bearer
create session my_session https://qa3-apiv2.xxx.com/oauth2 verify=${True}
${data1}= create dictionary grant_type=password client_id=9cde7c7dcf4d47772a068bf24ca0f518657a5f84 client_secret=cf102c871fe20a85c3dfb9d4d114eebccace168b username=qa3test_admin password=Password123#
${resp}= Post Request my_session /token.php data=${data1}
Should Be Equal As Strings ${resp.status_code} 200
${token}= evaluate $resp.json().get("access_token")
Log ${resp.content}
来源:https://stackoverflow.com/questions/50910964/how-to-generate-oauth-2-0-token-using-create-client-oauth2-session-keyword-in