我正在尝试创建一个自定义方法,该方法将生成一个字符串并放置一个条件==>如果生成的值已经在数据库中,则必须生成一个新值。为简化起见,下面的代码将生成一个随机字符串,我手动更改“ ABC”的结果值以确保达到循环条件。问题是,一旦“ While”条件被称为“ clientValue”为空。我的变量“ Let clientValue”似乎无法访问。
it('test', () => {
let clientValue = ''
do {
cy.getRandomString(3).then((response) => {
clientValue = response;
cy.log(clientValue)
clientValue = 'ABC'; // I change the value here to make sure I get into the loop with the condition below
cy.log(clientValue) // Print = ABC
});
}
while (clientValue === 'ABC'); // Condition is never true because the 'clientValue' is empty at this stage
cy.log(clientValue) // Print = Empty ??
});