Errores no bloqueantes del método de aserción Pytest-check

La víspera del inicio del curso " Python QA Engineer " , se preparó una traducción de material útil para futuros estudiantes y todos los interesados ​​en el tema de las pruebas.



También lo invitamos a ver una lección de demostración sobre el tema "Carrera profesional de calidad".










Existe un gran debate en la comunidad de pruebas sobre cuántas afirmaciones deben haber en una prueba de IU automatizada. Algunas personas piensan que debería haber una afirmación por prueba, es decir, cada prueba debería marcar solo un elemento. Otros están muy contentos de que su prueba verifique varios elementos a la vez. 





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





, :





, , , . , — , , . 





, , .





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