簡體   English   中英

Testcafe - 測試多個頁面

[英]Testcafe - Test multiple pages

我正在測試一個帶有登錄頁面的網站,然后其他頁面僅在登錄后可見。

我創建了一個login_page.js模型如下:

// my_login_page_model.js
import { Selector, t } from 'testcafe';

export default class LoginPage {
  constructor () {
    this.email = Selector('#email');
    this.password = Selector('#password');
    this.signin = Selector('#signinButton');
  }
}

然后我在登錄后為頁面創建了類似的頁面模型。

在我的測試文件中,然后實例化一個登錄頁面對象,運行登錄頁面測試

// my_test_spec.js
test('login in', async t => {
  await t
    .typeText(loginPage.email, config.name)
    .typeText(loginPage.password, config.password)
    .click(loginPage.signin);
  await t.expect(getURL()).contains(pageUrl);
});

test('second test', async t => {
console.log('Creating a new experience');
  await t
    .click(// click a button on the following page);
});

問題是第二次測試從login page開始,當然失敗了,因為它在登錄后找不到頁面的id。

如何才能做到這一點?

每個測試都從頭開始,這意味着干凈的配置文件,這就是為什么您在第二次測試開始時未被授權的原因。 最簡單的修復方法是在第二次測試開始時移動登錄代碼。 但是,這不是一個好習慣,因為您可能需要在大部分測試之前獲得授權。 要解決此問題,您可以選擇以下之一:

1) 某些情況下的Http Auth

2) 角色

3) 使用beforeEach Hook 只需將登錄代碼放入這個鈎子,它就會在夾具中的每個測試之前執行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM