Robotframework:JavaScript替换字符串不起作用

时间:2019-06-21 13:59:48

标签: javascript selenium robotframework

我正在编写一些Robotframework测试,并且需要重定向到其他URL,以防AB测试启动。

我尝试使用内建和硒,但是我发现自己使用JS更自在,这就是我写的来做的事情:

var url = location.href.toString();

function check(){
if (url.includes("preventivo-c")){
    return true;
 }
};
check();
if (check() === true){
    let newUrl = url.replace("preventivo-c", "preventivo");
    window.location.href = newUrl;
};

内部机器人是这样的:

${prevNew}=    execute javascript             const url = location.href.toString();       function check(){if (url.includes("preventivo-c")){return true;}};   check();    if (check() === true){let newUrl = url.replace("preventivo-c", "preventivo");window.location.href = newUrl;};

执行测试时,它会显示

InvalidArgumentException: Message: invalid argument: 'url' must be a string

我尝试在Chrome控制台上调试代码,但工作正常。 Console.log(typeof url)返回“字符串”,所以我不明白为什么会收到此错误。

0 个答案:

没有答案