问题描述
我试图让 CodeceptJS 在单击链接后等待页面加载,但我无法让它优雅地这样做。
我的 Ionic 页面:
主页
<IonPage>
<IonHeader>
<IonToolbar>
<IonButtons slot="start">
<IonBackButton />
</IonButtons>
<IonTitle>Main page</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent>
<Link to="reset-password">Reset Password</Link>
</IonContent>
</IonPage>
重置密码页面
<IonPage>
<IonHeader>
<IonToolbar>
<IonButtons slot="start">
<IonBackButton />
</IonButtons>
<IonTitle>Reset your password</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent>
Here is a form.
</IonContent>
</IonPage>
我的 codeceptJS 测试(使用 Playwright):
Scenario('Reset password',async ({ I }) => {
I.amOnPage('/');
I.wait('ion-button');
I.click('Reset Password');
// Wait for URL to change; doesn't help.
I.waitInUrl('/reset-path')
// Wait for "Reset Password" link to disappear; doesn't help.
I.waitForInvisible('Reset Password');
// Wait for new title text to appear; doesn't help.
I.waitForText('Reset your password');
// Simply wait 1 second; this is the only way to make sure the page is loaded.
I.wait(1);
const titleText = await I.grabTextFrom('ion-toolbar ion-title');
assert.strictEqual('Reset your password',titleText);
});
如果我不等待 1 秒,则会出现以下错误:
Expected values to be strictly equal:
+ actual - expected
+ 'Reset your password'
- 'Main page'
因此,即使我告诉 CodeceptJS 等到新的标题文本可见,它还是会以某种方式看到旧的标题文本,除非我硬编码等待时间。当然我做错了(今天刚开始使用 CodeceptJS),并且有一种方法可以优雅地强制它等待 Ionic 页面转换发生。我该怎么做?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)