implicit assertion(隱含斷言)
常用的 should 關鍵字:
be.visible:確保元素在畫面上可見。 
be.hidden:確保元素在畫面上隱藏。 
be.checked:確保複選框或單選框元素被選中。 
be.disabled:確保元素被禁用。 
have.text:檢查元素的文字內容是否符合預期。 
have.value:檢查輸入元素的值是否符合預期。 
have.attr:檢查元素的特定屬性值是否符合預期。 
have.class:檢查元素是否具有特定的類名。 
contain:檢查元素是否包含指定的文字內容。 
可根據具體需求進行選擇和使用
keywords
這裡的練習範例,驗證當前網址(URL)的斷言方法。
include:確保當前網址包含特定的子字串。
1 2
   | cy.url().should('include', '/login');
 
  | 
 
eq:確保當前網址與預期值完全相等。
1 2
   | cy.url().should('eq', 'https://example.com/dashboard');
 
  | 
 
contain:檢查當前網址是否包含特定的字串。
1
   | cy.url().should('contain', 'example.com');
  | 
 
這些斷言方法可用於驗證當前網址是否符合預期,從而確保導航或操作正確導致了預期的網址變化。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
   | describe("Assertion practice",()=>{
  	it("explicit", ()=>{ 	 		cy.visit('https://opensource-demo.orangehrmlive.com/web/index.php/auth/login') 		 		 		 		cy.url().should('include', 'orangehrmlive.com') 		 		cy.url().should('eq', 'https://opensource-demo.orangehrmlive.com/web/index.php/auth/login') 		 		cy.url().should('contain', 'orangehrmlive') 		 	 	})
  })
 
  | 
 
1 2 3 4 5
   | cy.url().should('include', 'orangehrmlive.com')
  .should('eq', 'https://opensource-demo.orangehrmlive.com/web/index.php/auth/login')
  .should('contain', 'orangehrmlive')
  | 
 
1 2 3 4 5
   | cy.url().should('include', 'orangehrmlive.com')
  .and('eq', 'https://opensource-demo.orangehrmlive.com/web/index.php/auth/login')
  .and('contain', 'orangehrmlive')
  | 
 
另外可以檢查進到頁面 logo 圖示的顯示
1 2 3 4 5 6 7 8 9 10
   |  describe("Assertion practice",()=>{   it("explicit", ()=>{     cy.visit('https://opensource-demo.orangehrmlive.com/web/index.php/auth/login')            cy.get('.orangehrm-login-branding > img').should('be.visible')     .and('exist')   }) })
 
 
  | 
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14
   |  describe("Assertion practice",()=>{   it("explicit", ()=>{     cy.visit('https://opensource-demo.orangehrmlive.com/web/index.php/auth/login')                   cy.get("input[placeholder='Username']").type("Admin")     cy.get("input[placeholder='Username']").should("have.value", "Admin")
         }) })
 
 
  | 
 
explicit assertion
(顯式斷言)」是指明確使用斷言方法來檢查特定的條件或預期結果。
與隱含斷言不同,顯式斷言需要您明確指定斷言方法來進行驗證。