Pytest-check assert method non-blocking error

Menjelang dimulainya kursus " Python QA Engineer " , terjemahan materi yang berguna disiapkan untuk siswa yang akan datang dan semua orang yang tertarik dengan topik pengujian.



Kami juga mengundang Anda untuk menonton demo-pelajaran dengan topik "QA Career".










Ada banyak perdebatan di komunitas pengujian tentang berapa banyak pernyataan yang harus ada dalam satu pengujian UI otomatis. Beberapa orang berpikir bahwa harus ada satu pernyataan per pengujian, artinya, setiap pengujian harus memeriksa hanya satu elemen. Yang lain cukup senang bahwa tes mereka memeriksa beberapa item sekaligus. 





Pendekatan mana pun yang Anda pilih, menurut saya aman untuk mengatakan bahwa pengujian harus tetap jelas, ringkas, dapat dibaca, dan tentu saja, harus mudah dipelihara. Secara pribadi, saya tidak punya masalah dengan beberapa pernyataan dalam satu pengujian, karena saya fokus pada satu area fungsional.





Sebagai contoh, mari kita ambil formulir pendaftaran:





, , , . , โ€” , , . 





, , .





assert Python , . . , . , , , assert- .





-. , , , , , , assert.





: Pytest-check

Pytest-check ( ) โ€“ Pytest, assert- pass/fail. , 3 assert- fail, Pytest-check 2. , , fail.





Python OpenSDK TestProject Pytest, pytest Selenium, TestProject. HowQA,





, Pytest-check.





Selenium

. : https://docket-test.herokuapp.com/register





import selenium.webdriver as webdriver
from selenium.webdriver.common.by import By
def test_register_user():
    # Arrange
    url = "https://docket-test.herokuapp.com/register"
    # set the driver instance
    driver = webdriver.Chrome()
    # browse to the endpoint
    driver.get(url)
    # maximise the window
    driver.maximize_window()
    # Act
    # Complete registration form
    # enter username value
    driver.find_element(By.ID, "username").send_keys("Ryan")
    # enter email value
    driver.find_element(By.ID, "email").send_keys("Test@email.com")
    # enter password value
    driver.find_element(By.ID, "password").send_keys("12345")
    # enter repeat password value
    driver.find_element(By.ID, "password2").send_keys("12345")
    # click register button
    driver.find_element(By.ID, "submit").click()
      
      



, . assert:





# Assert
# confirm registration has been successful
# check if congratulations message contains the correct text
message = driver.find_element(By.XPATH, "/html[1]/body[1]/div[1]/div[1]/div[1]/div[1]/form[1]/div[1]").text
assert message == "Congratulations, you are now registered"
# check user is routed to login page
current_url = driver.current_url
assert current_url == "https://docket-test.herokuapp.com/login"
      
      



, :





, , assert- fail? , , :





# Assert
# confirm registration has been successful
# check if congratulations message contains the correct text
message = driver.find_element(By.XPATH, "/html[1]/body[1]/div[1]/div[1]/div[1]/div[1]/form[1]/div[1]").text
assert message == "Well done, You've Registered"
# check user is routed to login page
current_url = driver.current_url
assert current_url == "https://docket-test.herokuapp.com/register"
driver.quit()
      
      



, , URL, , , fail:





, assert. , , , , - โ€ฆ





, - , URL . , fail, . . .





ยซCongratulations, you are now registeredยป, :





! , - URL.





, , , . , , Pytest-check.





Pytest-Check

pytest-check pip install pytest-check



. pytest-check, .





import pytest_check as check
      
      



, , assert-. assert, pytest-check . 





check.equal



, :





check.equal(message, "Congratulations, you are now registered1")
      
      



URL-, , check.is_in



.





check.is_in("login", current_url)
      
      



:





import selenium.webdriver as webdriver
from selenium.webdriver.common.by import By
import pytest_check as check
def test_register_user():
    # Arrange
    url = "https://docket-test.herokuapp.com/register"
    # set the driver instance
    driver = webdriver.Chrome()
    # browse to the endpoint
    driver.get(url)
    # maximise the window
    driver.maximize_window()
    # Act
    # Complete registration form
    # enter username value
    driver.find_element(By.ID, "username").send_keys("Ryan8")
    # enter email value
    driver.find_element(By.ID, "email").send_keys("Test@email8.com")
    # enter password value
    driver.find_element(By.ID, "password").send_keys("12345")
    # enter repeat password value
    driver.find_element(By.ID, "password2").send_keys("12345")
    # click register button
    driver.find_element(By.ID, "submit").click()
    # Assert
    # confirm registration has been successful
    # check if congratulations message contains the correct text
    message = driver.find_element(By.XPATH, "/html[1]/body[1]/div[1]/div[1]/div[1]/div[1]/form[1]/div[1]").text
    check.equal(message, "Congratulations, you are now registered")
    # check user is routed to login page
    current_url = driver.current_url
    check.is_in("login", current_url)
    driver.quit()
      
      



, . .





! , , fail. , :





# check if congratulations message contains the correct text
message = driver.find_element(By.XPATH, "/html[1]/body[1]/div[1]/div[1]/div[1]/div[1]/form[1]/div[1]").text
check.equal(message, "Congratulations, you are now registered!")
# check user is routed to login page
current_url = driver.current_url
check.is_in("1", current_url)
      
      



.





, , , , fail : , , URL. pytest, , - , fail. 





, pass.





Pytest-check. .






- "Python QA Engineer".









- - " QA".












All Articles