Library REST ${base_url}
*** Keywords ***
Get Requests
GET ${rest_of_the_url}
Output response body
*** Test Cases ***
Do some searching
Get Requests
*** Variables ***
${base_url} https://business.com
${rest_of_the_url} /api/${department}/${person_name}
如何为$ {department}和$ {person_name}赋值?我不想在 Variables 中设置它们,因为那样我就不能在一个.robot文件中编写多个方案。可以将赋值作为参数吗?
答案 0 :(得分:1)
我认为没有办法在变量内传递参数
以下部分直接来自Robotframework文档, 您可以在其中创建变量内部的变量
变量内的变量 变量内部也可以使用变量,使用此语法时,变量由内而外解析。例如,如果您有变量$ {var $ {x}},则首先解析$ {x}。如果它具有值名称,则最终值就是变量$ {varname}的值。可以有多个嵌套变量,但是如果没有任何嵌套变量,则解析最外层失败。
在下面的示例中,Do X获得值$ {JOHN HOME}或$ {JANE HOME},具体取决于Get Name返回的是john还是jane。如果返回其他内容,则无法解析$ {$ {name} HOME}。
class mySpider(CrawlSpider):
name = 'mySPider'
allowed_domains = ['allowedDOmain.org']
start_urls = ['https://url.org']
def parse(self,response):
monthSelector = '//div[@class="archives-column"]/ul/li/a[contains(text(),"November 2019")]/@href'
monthLink = response.xpath(monthSelector).extract_first()
yield response.follow(monthLink,callback=self.scrape)
def scrape(self,response):
# get the links to all individual articles
linkSelector = '.entry-title a::attr(href)'
allLinks = response.css(linkSelector).extract()
for link in allLinks:
# item = articleItem()
item = ProjectItem()
item['url'] = link
request = response.follow(link,callback=self.getContent)
request.meta['item'] = item
item = request.meta['item']
yield item
nextPageSelector = 'span.page-link a::attr(href)'
nextPageLink = response.css(nextPageSelector).extract_first()
yield response.follow(nextPageLink,callback=self.scrape)
def getContent(self,response):
item = response.meta['item']
TITLE_SELECTOR = '.entry-title ::text'
item['title'] = response.css(TITLE_SELECTOR).extract_first()
yield item
答案 1 :(得分:0)
例如,
// loadInitialData.js
import {
SET_DIETS_LIST,
UPDATE_FILTERS_FROM_CACHE,
} from "Store/types";
import fetch from "isomorphic-unfetch";
export default dispatch => {
const ls = JSON.parse(localStorage.getItem("filters"));
if (ls) {
const localStorageState = {
diet: {
list: ls.diet.list || [],
selected: ls.diet.selected || [],
},
...
};
dispatch({
type: UPDATE_FILTERS_FROM_CACHE,
payload: { filters: localStorageState },
});
}
if (!ls || !ls.diet.list.length) {
fetch(`${process.env.API_URL}/diets`)
.then(r => r.json())
.then(data => {
dispatch({ type: SET_DIETS_LIST, payload: { data[0] } });
});
}
...
};
Set Variable文档。
答案 2 :(得分:0)
我觉得在这种情况下,您可以尝试使用机器人框架的数据驱动方法。
https://thinkpalm.com/blogs/data-driven-testing-robot-framework/
答案 3 :(得分:0)
尝试在此处使用“设置测试/套件/全局变量”关键字查看此内容: https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html
使用“设置套件变量”关键字,然后输入变量$ {person_name} e $ {department}放在 *变量* 中,那么您应该读取测试中的值。