Home > Blockchain >  Capturing data from dropdown dynamically using pytest parameterization
Capturing data from dropdown dynamically using pytest parameterization

Time:02-12

I have a testdata sheet where I am providing the suminsured value, the same should be select from the suminsured dropdown available in the web page. Following is the code written in the BasePage where I am defining the select class to identify the dropdown

def SelectSumInsured(self,sumvalue):
    sumdropdown = Select(self.driver.find_element(By.XPATH, "//select[@formcontrolname = 'income']"))
    suminsured = sumdropdown.select_by_value(sumvalue)
    return suminsured

Now in the page object screen, I am inheriting the BasePage and defined functions like below

class HealthInsurancePage(BasePage):

    def __init__(self, driver):
        super().__init__(driver)


    def SelectSum(self,sumvalue):
        self.SelectSumInsured(sumvalue)

Now in the testscript, I have used pytest parameterized for the data driven approach which should select the dropdown value as per my data I have provided in the excel sheet

class Test_RSA_Health(BaseTest):

@pytest.mark.parametrize("pin,sumvalue", dataProvider.get_data("excelsheetname"))
def test_RSA_Health(self,pin,sumvalue):
    home = HomePage(self.driver)
    healthinsuranepage = home.SelectHealth()
    self.VerifyPresence_PinCodeTextBox()
    healthinsuranepage.landing_page()
    healthinsuranepage.InputPin(pin)
    healthinsuranepage.SelectSum(sumvalue)

For inputting the pin for a text field, is working fine but when I am trying to select from any dropdown, I am having the below error

TypeError: argument of type 'int' is not iterable

As requested, find below the complete error stack

platform win32 -- Python 3.9.7, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- C:\Users\aprat\AppData\Local\Programs\Python\Python39\python.exe
cachedir: .pytest_cache
metadata: {'Python': '3.9.7', 'Platform': 'Windows-10-10.0.19042-SP0', 'Packages': {'pytest': '6.2.5', 'py': '1.11.0', 'pluggy': '1.0.0'}, 'Plugins': {'allure-pytest': '2.9.45', 'ast-t
ransformer': '1.0.3', 'pytest_check': '1.0.4', 'forked': '1.3.0', 'html': '3.1.1', 'metadata': '1.11.0', 'rerunfailures': '10.2', 'server-fixtures': '1.7.0', 'shutil': '1.7.0', 'soft-a
ssertions': '0.1.2', 'xdist': '2.4.0'}, 'JAVA_HOME': 'C:\\Program Files\\Java\\jre1.8.0_301'}
rootdir: C:\Users\aprat\PycharmProjects\Demo-Web-Automation\TestCases
plugins: allure-pytest-2.9.45, ast-transformer-1.0.3, pytest_check-1.0.4, forked-1.3.0, html-3.1.1, metadata-1.11.0, rerunfailures-10.2, server-fixtures-1.7.0, shutil-1.7.0, soft-asser
tions-0.1.2, xdist-2.4.0
collecting ... total cols are  19
total rows are  3
[[560008, 700000, 9836680067, 30, 'Apratim Chaudhuri', '[email protected]', 'Apratim', 'Chaudhuri', '1/2/1992', 1000000, 'AMHPC9725D', 'QA', 'GD', 'SaltLake', 180, 75, 'te
stnomineefirst', 'testnomineelast', '1/2/1992']]
[[560008, 700000, 9836680067, 30, 'Apratim Chaudhuri', '[email protected]', 'Apratim', 'Chaudhuri', '1/2/1992', 1000000, 'AMHPC9725D', 'QA', 'GD', 'SaltLake', 180, 75, 'te
stnomineefirst', 'testnomineelast', '1/2/1992'], [560008, 500000, 9836680067, 30, 'Apratim Chaudhuri', '[email protected]', 'Apratim', 'Chaudhuri', '1/2/1992', 1000000, 'A
MHPC9725D', 'QA', 'GD', 'SaltLake', 180, 75, 'testnomineefirst', 'testnomineelast', '1/2/1992']]
collected 2 items                                                                                                                                                                      

test_RSA_Health.py::Test_RSA_Health::test_RSA_Health[560008-700000-9836680067-30-Apratim [email protected]/2/1992-1000000-AMHPC9725D-QA-GD-Sa
ltLake-180-75-testnomineefirst-testnomineelast-1/2/1992]
DevTools listening on ws://127.0.0.1:55170/devtools/browser/d421fa5e-76f4-4af6-8542-d3c80ff44613
[24148:11008:0212/005823.767:ERROR:chrome_browser_main_extra_parts_metrics.cc(227)] START: ReportBluetoothAvailability(). If you don't see the END: message, this is crbug.com/1216328.
[24148:11008:0212/005823.767:ERROR:chrome_browser_main_extra_parts_metrics.cc(230)] END: ReportBluetoothAvailability()
[24148:11008:0212/005823.769:ERROR:chrome_browser_main_extra_parts_metrics.cc(235)] START: GetDefaultBrowser(). If you don't see the END: message, this is crbug.com/1216328.
[24148:9888:0212/005823.772:ERROR:device_event_log_impl.cc(214)] [00:58:23.773] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to
the system is not functioning. (0x1F)
[24148:11008:0212/005823.790:ERROR:chrome_browser_main_extra_parts_metrics.cc(239)] END: GetDefaultBrowser()
FAILED

====================================================================================== FAILURES =======================================================================================
_ Test_RSA_Health.test_RSA_Health[560008-700000-9836680067-30-Apratim [email protected]/2/1992-1000000-AMHPC9725D-QA-GD-SaltLake-180-75-testn
omineefirst-testnomineelast-1/2/1992] _

self = <TestCases.test_RSA_Health.Test_RSA_Health object at 0x0000022C0C64BBB0>, pin = 560008, sumvalue = 700000, mobileno = 9836680067, selfage = 30, fullname = 'Apratim Chaudhuri'
email = '[email protected]', firstname = 'Apratim', lastname = 'Chaudhuri', dob = '1/2/1992', income = 1000000, pan = 'AMHPC9725D', designation = 'QA', add1 = 'GD'
add2 = 'SaltLake', height = 180, weight = 75, nomfirstname = 'testnomineefirst', nomlastname = 'testnomineelast', nomdob = '1/2/1992'

    @pytest.mark.parametrize("pin,sumvalue,mobileno,selfage,fullname,email,firstname,lastname,dob,income,pan,designation,add1,add2,height,weight,nomfirstname,nomlastname,nomdob", dataP
rovider.get_data("rsa_health"))
    def test_RSA_Health(self,pin,sumvalue,mobileno,selfage,fullname,email,firstname,lastname,dob,income,pan,designation,add1,add2,height,weight,nomfirstname,nomlastname,nomdob):
        home = HomePage(self.driver)
        healthinsuranepage = home.SelectHealth()
        self.VerifyPresence_PinCodeTextBox()
        healthinsuranepage.landing_page()
        healthinsuranepage.InputPin(pin)
>       healthinsuranepage.SelectSum(sumvalue)

test_RSA_Health.py:17:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\Pages\HealthInsurancePage.py:24: in SelectSum
    dropdown.select_by_value(sumvalue)
..\..\..\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\support\select.py:78: in select_by_value
    css = "option[value =%s]" % self._escapeString(value)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <selenium.webdriver.support.select.Select object at 0x0000022C0C679CD0>, value = 700000

    def _escapeString(self, value):
>       if '"' in value and "'" in value:
E       TypeError: argument of type 'int' is not iterable

..\..\..\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\support\select.py:219: TypeError
---------------------------------------------------------------------------------- Captured log call ----------------------------------------------------------------------------------
INFO     Pages.BasePage:BasePage.py:27 Clicking on an Element health_XPATH
INFO     Pages.BasePage:BasePage.py:60 Typing in an Element pin_XPATH entered the value as : 560008
=============================================================================== short test summary info ===============================================================================
F

CodePudding user response:

This error message...

    css = "option[value =%s]" % self._escapeString(value)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <selenium.webdriver.support.select.Select object at 0x0000022C0C679CD0>, value = 700000

    def _escapeString(self, value):
>       if '"' in value and "'" in value:
E       TypeError: argument of type 'int' is not iterable

...implies that select_by_value(value) expects the value to be in string format. Where as, in your usecase sumvalue was an interger.


Solution

Convert sumvalue as a str while passing as an argument to SelectSum() as follows:

healthinsuranepage.SelectSum(str(sumvalue))
  • Related