在脚本中调用函数文件中的ClientFunction时未执行

时间:2019-06-04 22:13:13

标签: javascript automated-tests e2e-testing web-testing testcafe

我在函数文件中创建了一个函数,因此可以在脚本中调用它。此功能与其他功能的不同之处在于,它是常规功能中的ClientFunction。在我的脚本文件中调用它没有任何作用。

我已经创建了函数,并导入和导出了所需的所有内容。我在脚本中调用该函数的方式与调用其余其他函数的方式相同。其他功能运行正常。

从我的功能文件'globalFunctions.js'

import {ClientFunction} from 'testcafe';

export async function scroll(){
  const scroll = ClientFunction(function() {
    window.scrollBy(0,1000)
});
  return(scroll);
};

从我的脚本文件

import * as globalFunctions from './global_functions.js';
globalFunctions.scroll(t)

我正在调用的其他功能也很好

globalFunctions.namegenerator(t)

预期:

当我调用函数scroll()时,页面应滚动到页面底部。

实际:

页面不会向下滚动,代码转到下一行,然后脚本无法显示找不到我的对象。

1 个答案:

答案 0 :(得分:3)

我将其功能更改为:

export const scroll = ClientFunction(function() {
    return window.scrollBy(0,1000)
});

并通过以下方式在我的脚本中调用它:

await globalFunctions.scroll()