How to do data-driven testing in selenium with python, and in what kind of case do we need to data-driven test?
Use pytest
library something as below code demonstrates.
import pytest
@pytest.mark.parametrize("num1, num2, output", [(10, 2, 5), (20, 10, 2)])
def testDivisionWithPositiveValues(CreateCalculatorClassObj, num1, num2, output):
result = CreateCalculatorClassObj.Division(num1, num2)
assert result == output
In the above code @pytest.mark.parametrize
is from pytest
library and it is used where you want to pass the data to the method. The mothod annotated with this annotation will automatically pick the data from it.