-4

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.

Helping Hands
  • 5,292
  • 9
  • 60
  • 127
  • Is it supposed to be an instance method? Your 3 arguments are `loginpage`, `context` and `Email` – Sayse Dec 10 '19 at 07:12
  • Does this answer your question? [TypeError: method() takes 1 positional argument but 2 were given](https://stackoverflow.com/questions/23944657/typeerror-method-takes-1-positional-argument-but-2-were-given) – Sayse Dec 10 '19 at 07:14
  • @Sayse - I already tried above but either it is not working or I am applying in an incorrect way. can you give me an example of how to apply with my code example? – Helping Hands Dec 10 '19 at 07:21
  • 2
    "Its not working" is not a description. Cant really help any more because as I said in the first comment, it's not clear what your function belongs to, or where the 3 parameters come from – Sayse Dec 10 '19 at 07:24
  • 2
    It's still not clear what `loginpage` is – Sayse Dec 10 '19 at 07:39
  • `Email` is a class, right? – AMC Dec 10 '19 at 07:48
  • @AlexanderCécile - No. Email is variable in my case. – Helping Hands Dec 10 '19 at 07:54
  • 1
    @HelpingHands Then why does its name contain a capital letter? – AMC Dec 10 '19 at 07:54
  • @AlexanderCécile - forgive me, I am moving from java to python and novice into python so you might see some naming issue. – Helping Hands Dec 10 '19 at 07:58
  • @HelpingHands It's fine, just bear in mind that function and variable names should generally follow the `lower_case_with_underscores` style. – AMC Dec 10 '19 at 07:58

2 Answers2

0

Based on the error message, it seems that you are passing three arguments to the enterEmail() method of the LoginPage class, while it only expects one argument.

In your Steps_Login.py file, you are passing context and Email as arguments to loginpage.enterEmail(context, Email), while the method only expects email as an argument.

To fix the issue, you should remove context from the argument list and only pass Email as an argument to enterEmail() method.

Here's the corrected code:

@Then('I enter valid "{Email}"')
def step_impl(Email):
    loginpage.enterEmail(Email)

By making this change, you should be able to pass the email correctly to the enterEmail() method.

-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.