Automated tests 我可以使用Testcafe执行Rendr应用程序功能吗?

Automated tests 我可以使用Testcafe执行Rendr应用程序功能吗?,automated-tests,e2e-testing,web-testing,testcafe,rendr,Automated Tests,E2e Testing,Web Testing,Testcafe,Rendr,我正在研究将TestCafe用作我的测试自动化框架,在使用AUT上的Rendr应用程序执行函数时遇到了一些障碍。 使用Cypress.io、量角器和木偶师等,我可以运行相同的命令。。。所以我不太确定TestCafe到底出了什么问题 基本上,我试图执行的是: window.App.get('currentUser').set('login_state','someLoginState') 柏树 cy.window().then((win) => { win.App.get('cu

我正在研究将TestCafe用作我的测试自动化框架,在使用AUT上的Rendr应用程序执行函数时遇到了一些障碍。 使用Cypress.io、量角器和木偶师等,我可以运行相同的命令。。。所以我不太确定TestCafe到底出了什么问题

基本上,我试图执行的是:
window.App.get('currentUser').set('login_state','someLoginState')

柏树

  cy.window().then((win) => {
    win.App.get('currentUser').set('login_state', 'someState');
  });
量角器

  function changeUserState() {
    App.get('currentUser').set('login_state', 'someState');
  }

  browser.executeScript(changeUserState);
  function changeUserState() {
    window.App.get('currentUser').set('login_state', 'someState');
  }

  await page.evaluate(changeUserState);
木偶演员

  function changeUserState() {
    App.get('currentUser').set('login_state', 'someState');
  }

  browser.executeScript(changeUserState);
  function changeUserState() {
    window.App.get('currentUser').set('login_state', 'someState');
  }

  await page.evaluate(changeUserState);
对于TestCafe,我尝试使用:

const changeUserState = ClientFunction((desiredState) => {
    return App.get('currentUser').set('login_state', desiredState);
});

fixture `User states`
    .page(url)
    .afterEach( async t => {
        await t
            logout();
    });

test('Change a users log in state', async t => {

    await loginForm.loginViaUrl(userEmail, userPassword);
    await changeUserState('SomeState');
    await checkUserState('SomeState');  // Just an example of what I would do next
}
运行此操作时,它抛出一个
ReferenceError:App未定义
错误

(我还尝试使用“window.App.get…”执行上述选项:
TypeError:无法读取未定义的属性“get”
-在调用ClientFunction之前添加等待不会影响输出)

更新
根据评论,在访问客户端功能时不应使用
t.eval(…)
选项。

我认为问题与未定义应用程序变量有关。因此,您应该等到它变得可用。您可以使用具有固定等待时间的等待操作,或使用以下选择器等待元素出现在页面上:

await Selector('element that tells us that App exists')
UPD:检查了您在中提供的测试示例后,我们为您找到了一个解决方案。必须等待
App
变量出现。在函数调用之前添加以下代码:

// first case
const getPageUrl = ClientFunction(() => location.toString());

await t.expect(getPageUrl()).eql('https://www.change.org/', { timeout: 5000 });
// second case
const isAppExists = ClientFunction(() => !!window.App);

await t.expect(isAppExists()).ok({ timeout: 5000 });
UPD来自:

import { Selector, ClientFunction } from 'testcafe';

fixture`Change User State`.page('www.change.org');

const isAppExists = ClientFunction(() => !!window.App);

const changeUserState = ClientFunction((desiredState) => {
    const initialState = App.get('currentUser').get('login_state');
    App.get('currentUser').set('login_state', desiredState);
    const currentState = App.get('currentUser').get('login_state');
    return { initialState, currentState };
});

test
    ('Start from homepage', async t => {
        await t
            .maximizeWindow()
            .navigateTo('/login_or_join')
            .typeText(Selector('#content input[type="email"]'), '*****')
            .typeText(Selector('#content input[type="password"]'), '*****')
            .click(Selector('#content input[type="submit"]'))
            .expect(isAppExists()).ok(); // wait for App

        console.log(await changeUserState('guest'));
});
结果:

Running tests in:
- Chrome 74.0.3729 / Windows 10.0.0

Change User State
{ initialState: 'authenticated', currentState: 'guest' }
 √ Start from homepage


 1 passed (15s)

无法对错误进行评论,但您肯定需要使用ClientFunction,因为测试代码是在服务器上执行的,而不是在浏览器中执行的。你需要像这里描述的那样使用窗口:谢谢,我想是这样的,我只想涵盖所有的基础:)。你能提供一个复制它的示例页面吗?使用
ClientFunction
的代码看起来有效。如果您试图在请求测试时执行它,则可能您的应用程序尚未初始化,请在执行
changeUserState
之前尝试添加
t.wait
。使用
window.App
或切换到特定的iframe或顶部窗口也可以帮助您。嗨@AndreyBelym,我将更新测试用例的更多细节。基本上,我登录到我们的网站,然后运行此代码将登录状态更改为“未验证”等。我没有示例页面,但是你可以访问www.change.org,使用Chrome开发工具控制台运行代码更新我的问题,以显示使用
t.wait
和使用
window.App的结果