Use of cookies landing robotframework

Some systems use cookies to keep landing, but there's no RF's Request library inside the same operation as Selenium2Library cookies keyword, if interfaces need to log in using UI Automation can only log in first, and then added to the header of cookies to maintain Log in state

 

table of Contents

1, Selenium2Library operation cookie

2, cookies applications

 

1, Selenium2Library operation cookie

# 1, add cookies, named key, value value 
the Add Key Cookie value 

# 2, delete all Cookies 
    the Delete All Cookies 

# 3, delete the name for the cookie key of 
    the Delete Cookie Key 

# 4, get all of Cookies 
    the Get Cookies 

# 5 to get the name value of the key value of the cookie, get cookie that is selenium2Library3.2 future version of the application 
    the get cookie 
    the get cookie value

 

 Application: The use cookie = $ {cookies} This cookie to the fixed format header to the incoming

2, cookies applications

The first step: the interface is judged by the packet capture tool holding cookie landing

Step Two: Import selenium2Library library

The third step: get the cookies UI written in a keyword landing, get the value of cookies as a return value and is set to global variables

 

    Open Browser    http://localhost:8090/jpress/admin/login    chrome
    Input Text    name=username    ${user}
    sleep    3
    Input Text    name=password    ${psw}
    Click Button    xpath=//*[@id="loginform"]/div[3]/div[2]/button
    ${m}    get cookies
    log    ${m}
    ${cookies}    get cookie value    user
    Set Global Variable    ${cookies}

 

Step four: the need to maintain the interface to incoming cookies landing

 

${cookies}	登录	root	123456
log	${cookies}		
${cookie}	Set Variable	user=${cookies}	
Create Session	api	http://localhost:8090/jpress	
${headers}	Create Dictionary	Content-Type=application/x-www-form-urlencoded	Cookie=${cookie}
${data}	Create Dictionary	user.username=test22	user.nickname=test22
${m}	Post Request	api	/admin/user/save
${i}	To Json	${m.content}	
${n}	Get From Dictionary	${i}	message
Should Contain	${n}	ok	

 

  

  

Guess you like

Origin www.cnblogs.com/weizhideweilai/p/11221410.html