LogoLogo
  • 🏹Lời nói đầu
  • 1. Introduction
  • 💡1.1. Các hoạt động trong 1 vòng kiểm thử
  • 💡1.2. Các cách tiếp cận khi viết automation test
  • 🔮1.3. Con đường phát triển của một kỹ sư kiểm thử phần mềm
  • ✅1.4. Quy trình của một dự án kiểm thử tự động
  • 🤖1.5. Các Framework trong kiểm thử tự động
  • 💎1.6. Selenium Java Basic mindmap
  • 📜1.7. Test cases
  • 2. Setup new maven project
    • ☕2.1. Install Java JDK
    • ☕2.2. Setup Maven
    • ☕2.3 Add Maven Dependencies
    • ☕2.4. Java practices
      • ⌨️2.4. Java Coding Practice
      • 📔Java Stream
        • 🍀Java 8 Stream - Xử lý Array, List nhanh gọn
          • 🛵1. find person that has mass >100
            • 🚜2. total mass of characters
            • 🚍3. total height of characters
            • 🚲4. get list name of person
            • 🛴5. find max mass person
            • 🚒6. find smallest person
            • 🚂7. sort by name
            • 🏎️8. sort by mass
      • 📁Logging
        • 🍏Log4j 2
  • 3. browsers
    • 🚚3.1. What is WebDriver?
    • 3.2. Chrome Browser
      • 🕸️Open Chrome Browser
        • Capture Performance metrics in chrome with selenium 4.0
        • Open Chrome Browser in Mobile mode
        • How to set specified chrome version to start
        • Interception Network tab
        • Open Chrome Browser - Headless mode
      • Fake GeoLocation
    • 3.3. Open Firefox Browser
      • Open Firefox Browser - Headless mode
    • 3.4. Open Edge Browser (Chromium)
    • 3.5. Open Safari browser
  • 🌞4. Inspect locators
  • 4.1. Understand HTML structure
  • 4.2. Locator Table
  • 4.3. Standard Naming Convention for UI Elements to Use with Selenium Locators
  • 4.4. FindElement
  • 4.5. Locating elements with XPath axis
  • 🍏5. Test Cases
    • 5.1. Form Authentication
    • 5.2. Drop Down
    • 5.3. Checkboxes
    • 5.4. Hyperlink
    • 5.5. Web Table
    • 5.6. JavaScript Alert
    • 5.7. Nest Frames
    • 5.8. Context menu
    • 5.9. Hover
    • 5.10. Broken Link
    • 5.11. Click Element via JS
    • 5.12. Wait for loading
    • 5.13. Pass params though XPath string
    • 5.14. Date picker
    • 5.15. Capture Screenshot
  • 6. TestNG
    • Annotations
    • testng.xml
      • parameter
      • Filter by group
      • Listener
      • Parallel
  • Capture screenshot when test failed
  • 🍐7. Page Object Model
    • What is?
    • Approach 1: Using String for exposing elements
    • Approach 2: Using By for exposing elements
    • Approach 3: Using PageFactory for exposing elements
    • Todo MVC sample page
      • page
      • supports
      • testcases
  • 8. Circle CI - Github Actions
    • Integrate Circle CI
  • 🥞9. Owner methods
    • Selenium owner methods
  • Interview
    • How I interview tester
      • 35 Challenging Interview Questions for Testers
    • Git căn bản
    • VSCODE
Powered by GitBook

Copyright @testingvn.com

On this page

Was this helpful?

  1. 5. Test Cases

5.12. Wait for loading

Loading là một trong những sự kiện mà khi làm việc với các trang web mình phải tìm cách làm việc với nó, tránh việc này ảnh hưởng test flow.

Selenium có 3 cách waits:

  • implicit wait hay là chờ cứng theo một mốc thời gian nhất định.

  • explicit wait hay chờ mềm sử dụng trạng thái của một đối tượng hay một trang web để chở trong một khoảng thời gian nhất định. Việc sử dụng explcit giúp linh hoạt trong thì thực thi kiểm thử tự động trong các điều kiện mạng nhanh chậm khác nhau hoặc trạng thái của các đối tượng thay đổi liên tục

  • fluent wait - đây là một cải tiến của explicit wait với nhiều điều kiện hơn

Đối với những dùng selenium hiện nay thường dùng explicit wait. Thông qua test case dưới đây mình cho mọi ngừoi hiểu rõ hơn cách dùng explicit wait

Test case

Steps

  • Open browser

  • Navigate to https://the-internet.herokuapp.com/dynamic_loading/1

  • Click on Start button

  • Wait process bar disappear

  • Check finish message

Test case as code

@Test 
void dynamicLoadingPage() { 
    WebDriver driver = new ChromeDriver(); 
    driver.get("https://the-internet.herokuapp.com/dynamic_loading/1");
    driver.findElement(By.xpath("//button[.='Start']")).click();

    WebDriverWait wait = new WebDriverWait(driver, 30);
    String finishLbl = wait.until(
            ExpectedConditions
                    .visibilityOfElementLocated(
                            By.id("finish")))
            .getText();

    Assert.assertEquals(finishLbl,"Hello World!");
}

More ...

  • Để có thể sử dụng explicit wait đầu tiên mình cần khởi tạo một biến wait:

WebDriverWait wait = new WebDriverWait(driver, 30);
  • Ở đây mình đưa vào 2 biến là driver và Maximum timeout in seconds = 30

  • Class ExpectedConditions cho chúng ta nhiều phương thức khác để chờ đối tượng. visibilityOfElementLocated: chờ đối tượng hiển thị trông DOM và trên UI.

Previous5.11. Click Element via JSNext5.13. Pass params though XPath string

Last updated 2 years ago

Was this helpful?

🍏