當我嘗試運行我的測驗時,我收到了這個錯誤。我是打字稿和劇作家的新手,但不是編程/測驗自動化。
這是登錄頁面代碼
import { Locator, Page } from "@playwright/test";
export class LoginPage {
readonly page: Page;
readonly input_userId: Locator;
readonly input_password: Locator;
readonly button_login : Locator;
constructor(page:Page){
// super(page)
this.input_userId = page.locator('id=loginForm:userNameInput');
this.input_password = page.locator('id=loginForm:passwordInput');
this.button_login = page.locator('id=loginForm:loginButton');
}
async goto(url:string) {
await this.page.goto(url);
}
async enterUserName(userName:string){
await this.input_userId.fill(userName)
}
async enterPassword(password:string){
await this.input_password.fill(password)
}
async clickLogin(){
await this.button_login.click();
}
}
這是我運行測驗的地方
import {test,expect,Page} from '@playwright/test'
import { LoginPage } from '../pages/loginPage'
test.describe('Login Page', async () => {
test('Login as a super user',async ({page}) => {
const loginpage = new LoginPage(page);
loginpage.goto('https:// Some_URL'); // This is failing here
loginpage.enterUserName('[email protected]');
loginpage.enterPassword('test')
loginpage.clickLogin();
})
});
TypeError:無法讀取未定義的屬性“goto”
有人可以讓我知道我做錯了什么嗎?
謝謝
uj5u.com熱心網友回復:
是瀏覽Page器interface頁面。你已經readonly page: Page在你的LoginPage班級中定義了,但是你沒有將它分配給任何東西。因此它對于LoginPage. 在您的建構式中,您應該呼叫this.page = page;
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/436903.html
