之前遇到的一個 case 差不多是這樣:一個網頁按第一次 click 會出現內容是 foo 的 alert ,第二次以後出現的 alert 內容則是 bar 。
一開始的想法是這樣:
| open | example | |
| clickAndWait | //button[@type='submit'] | |
| verifyAlert | foo | |
| pause | 5000 | |
| open | example | |
| clickAndWait | //button[@type='submit'] | |
| verifyNotAlert | foo | |
| verifyAlert | bar |
跑起來以後卻一直出現 [error] There were no alerts 的警告。
後來想說調換順序:
| open | example | |
| clickAndWait | //button[@type='submit'] | |
| verifyAlert | foo | |
| pause | 5000 | |
| open | example | |
| clickAndWait | //button[@type='submit'] | |
| verifyAlert | bar | |
| verifyNotAlert | foo |
結果還是一樣出現 error 。最後終於知道問題在哪裡:
| open | example | |
| clickAndWait | //button[@type='submit'] | |
| verifyAlert | foo | |
| pause | 5000 | |
| open | example | |
| clickAndWait | //button[@type='submit'] | |
| verifyAlert | bar |
原因是一個 verifyAlert 或者 verifyNotAlert 就是要用掉一個實際上的 alert ,所以既然第二次的 alert 內容是 bar 不是 foo ,就直接驗證第二次的內容即可。
留言列表

💻️ 