1

I am learning Selenium with python, so please excuse my amateur questions, I am trying to run a simple Data driven test where selenium will enter a few different names on the Name field.

The Page code is as below:

class AddClients(BasePage): 
    log = cl.customLogger(logging.DEBUG) 
    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver

    def appy(self,name):                     
        self.clickAddBtn()
        self.enterEmpname(name)
        time.sleep(2)
        self.clickCancel()

I am running the tests on a different script

from pages.clients.addclient_page import AddClients
from utilities.teststatus import TestStatus
import unittest
import pytest
from ddt import ddt,data, unpack


@pytest.mark.usefixtures("oneTimeSetUp","setUp")
@ddt
class AddClientTest(unittest.TestCase):

    @pytest.fixture(autouse=True)
    def classSetup(self,oneTimeSetUp):
        self.ac = AddClients(self.driver)
        self.ts = TestStatus(self.driver)


    @pytest.mark.run(order=1)
    @data(("employeronefffffffffffffffffffffffffffffff"),("tester"))
    @unpack
    def test_adding_client(self,naming):
        self.ac.appy(naming)
        time.sleep(3)

But when I try to run the script it throws the error below:

============================= test session starts =============================
platform win32 -- Python 3.5.2, pytest-3.0.2, py-1.4.31, pluggy-0.3.1 -- c:\program files (x86)\python35-32\python.exe
cachedir: .cache
rootdir: C:\Users\Fake\PycharmProjects\Kode, inifile:
collected 0 items / 1 errors 

============================== ERRORS ===============================
____________ ERROR collecting tests/clients/addclient_test2.py ____________
c:\program files (x86)\python35-32\lib\site-packages\_pytest\python.py:209: in fget
    return self._obj
E   AttributeError: 'Module' object has no attribute '_obj'

During handling of the above exception, another exception occurred:
tests\clients\addclient_test2.py:11: in <module>
    class AddClientTesttwo(unittest.TestCase):
c:\program files (x86)\python35-32\lib\site-packages\ddt.py:258: in ddt
    add_test(cls, test_name, func, **v)
E   TypeError: add_test() argument after ** must be a mapping, not str
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.32 seconds ===========================

I am running all the test on py.test. Note: the browser doesn't even launch.

@data(('emploer',''), ('tester',''))

When I add a null value to data, the browser launches and does the sign in process but then fails with:

    self = <tests.clients.addclient_test2.AddClientTesttwo testMethod=test_adding_client_1___emploer____tester__>

    @wraps(func)
    def wrapper(self):
>       return func(self, *args, **kwargs)
E       TypeError: test_adding_client() takes 2 positional arguments but 3 were given

c:\program files (x86)\python35-32\lib\site-packages\ddt.py:139: TypeError
  • 1
    It's pretty complicated code. What are your Python and Selenium skills: Are you expert python coder? Do you have some simpler example where browser does launch? Can you distill some smaller example which still fails? – Peter M. Jan 19 '17 at 19:02
  • It looks like you gave the code for addclient_test.py, not addclient_test2.py, which is where the error is coming from . . . . – ernie Jan 20 '17 at 19:49
  • Actually that wasn't the issue I pasted the wrong error message from addclient_test here. I figured out the issue was I was using the "unpack" decorator, even though just one argument was required "naming" "unpack" decorator should only be used when you have more than one argument. – Ronron Jan 24 '17 at 20:26
1

I was using the @Unpack decorator on

@data(("employeeeee"),("testeeer"))
def test_adding_client(self,naming):

Looks like the unpack decorator should be used when there are more than one arguments

@data(("employeeeee","CEO"),("testeeer","CFO"))
@unpack
def test_adding_client(self,naming,position1):

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.