Getting error about argument when calling method

37
December 11, 2019, at 00:10 AM

I have feature file from where I am trying to get the email :

Scenario: Login to website
  Given I navigate to Login page
  When  I click on login button
  Then  I redirected to login page
  Then  I enter valid "<Email>"
        | Email |
        | test  |
  When  I click on Submit

I have below code in LoginPage.py :

from Base.BasePage import BasePage
from Base.WebDriverActions import Seleniumdriver

class LoginPage():
    instance = None
    @classmethod
    def get_instance(cls):
        if cls.instance is None:
            cls.instance = LoginPage()
        return cls.instance
    def __init__(self):
        self.driver = BasePage.get_driver()

  def enterEmail(self, email):
        self.driver.implicitly_wait(20)
        self.driver.find_element_by_id("login").send_keys(email)

When I call the above method into steps :

from Base.BasePage import BasePage
from behave import step, Given, When, Then
from Pages.LoginPage import loginpage

@Given('I navigate to Login page')
def step_impl(Context):
    BasePage.load_BaseURL();

@When('I click on login button')
def step_impl(Context):
    loginpage.clickLoginLink()

@Then('I redirected to login page')
def step_impl(self):
    print('Verifying user logged in..')
@Then('I enter valid "{Email}"')
def step_impl(Email):
    loginpage.enterEmail(Email);

I have below error :

  File "..\steps\Steps_Login.py", line 27, in step_impl
      loginpage.enterEmail(context, Email);
  TypeError: enterEmail() takes 1 positional argument but 3 were given

I tried by adding ** with an argument but no luck.

Answer 1

You are calling enterEmail as loginpage.enterEmail(context, Email) here you are passing arguments to the method as follows

  1. context
  2. Email
  3. Self for class loginpage

Try removing loginpage or context if it works.

READ ALSO
How to save results of lenghty calculation with multiple parameters?

How to save results of lenghty calculation with multiple parameters?

I am doing some lengthy calculations with multiple parametersI would like to save and retrieve the results of these calculations

53
Deleting elements from list not results as expected [duplicate]

Deleting elements from list not results as expected [duplicate]

I'm new to python, just exploring list in python

27
Parsing table to csv Python

Parsing table to csv Python

I need to parse table from https://egehse

24
pserve not working inside docker container

pserve not working inside docker container

I am trying to develop pyramid application with using docker-containerI build a docker images with below docker file

49