【发布时间】:2020-02-22 15:40:11
【问题描述】:
机器人测试
*** Settings ***
Variables test_if_case_sensitive.py
Documentation Suite description
Library Process
*** Variables ***
${pw1} "HeLLo1234"
${pw2} "hello1234"
${test3}
*** Test Cases ***
Test1
${test1}= set variable ${passwordWithCaps}
${test2}= set variable ${passwordWithoutCaps}
${test1}= set variable ${pw1}
${test2}= set variable ${pw2}
${test3}= set variable ${message}
Start Process python3 test_if_case_sensitive.py
Check If It Works
*** Keywords ***
Check If It Works
PASS EXECUTION IF ${test3} == "Passwords do not match"
这是python脚本
#test_if_case_sensitive.py
import socket
import string
import random
global passwordWithCaps
global passwordWithoutCaps
global message
def randomString(stringLength):
"""Generate a random string of fixed length """
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(stringLength))
def test_check_if_passwords_match_case_sensitive_when_creating_them(passwordWithCaps, passwordWithoutCaps):
username = randomString(random.randint(10, 20))
confirm_password = False
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
IP_address = "127.0.0.1"
Port = 8081
server.connect((IP_address, Port))
while True:
message = server.recv(2048).decode("utf-8")
if message:
print("Message 1" + message)
if confirm_password:
print("Message 2" + message)
if message.__contains__("You have successfully registered"):
raise Exception("Passwords match when they shouldn't")
break
if message.__contains__("Please enter username"):
server.send("--register".encode())
if message.__contains__("Please enter a username to register"):
server.send(username.encode())
if message.__contains__("Please create a password"):
server.send(passwordWithCaps.encode())
if message.__contains__("Please confirm password"):
confirm_password = True
server.send(passwordWithoutCaps.encode())
print(message)
test_check_if_passwords_match_case_sensitive_when_creating_them(passwordWithCaps, passwordWithoutCaps)
我正在尝试使用变量 ${pw1} 和 ${pw2} 从机器人测试脚本中分配全局变量 passwordWithCaps 和 passwordWithoutCaps。相反,我收到一条错误消息,提示未定义“passwordWithCaps”,这表明问题源于 python 脚本。但是,我在机器人测试中也得到了这个 -
Test1 | FAIL |
Variable '${passwordWithCaps}' not found.
【问题讨论】:
-
您是否看过 Robot Framework User Guide 部分Creating Test Libraries,其中包含用于创建自定义 Python 库的实用 Pyhton 示例?
标签: python robotframework