.json文件中的单独定位符-Cypres

时间:2019-01-18 16:18:46

标签: testing qa cypress

在与赛普拉斯一起工作时,是否可以在.json文件中分隔定位符? 我似乎无法在网上找到任何有关此的信息,但似乎应该可以实现。

我将定位器分离到一个.json文件中,但是在测试中调用它们时遇到了问题。

2 个答案:

答案 0 :(得分:3)

I haven't heard of anyone doing this and I wouldn't recommend it - storing selectors in the tests is the best method IMO. However if you're set on it you could store them in a file in the fixtures directory, then access them with cy.fixture(). Something like this:

cy.fixture('selectors.json').then(selectors => {
  cy.get(selectors.mySelector).click()
})

答案 1 :(得分:1)

另一个选择是将选择器加载到before()

let selectors;
before(function(){
  cy.fixture('selectors').then(s => selectors = s)
})

it('...', () => {
  cy.get(selectors.mySelector).click()
})