0

Here is the page object file: login.py

from pages.base import BasePage
from config import secrets
from selenium.webdriver.common.keys import Keys

class LoginPage(BasePage):

    def __init__(self):
        self.webdriver = BasePage.webdriver
        port = raw_input("Enter port number: ")
        self.url = "http://localhost:" + port

    @property
    def retrieve_username_field(self):
        self.webdriver.find_element_by_name("username")

    @property
    def retrieve_password_field(self):
        self.webdriver.find_element_by_name("password")

    def login(self, username=None, password=None):
        username = username or secrets.username
        password = password or secrets.password
        self.retrieve_username_field.send_keys(username)
        self.retrieve_password_field.send_keys(password)
        self.retrieve_password_field.send_keys(Keys.RETURN)

Here is the base page file: base.py

from selenium import webdriver

class BasePage(object):
    webdriver = webdriver.Firefox()

    def go(self):
        self.webdriver.get(self.url)

Here is the test file: test_login.py

import unittest

from pages.login import LoginPage

login_page = LoginPage()

def setUpModule():
    login_page.go()

def tearUpModule():
    login_page.logout()


class TestLogin(unittest.TestCase):

    def test_login_succeeds_with_valid_credentials(self):
        login_page.login()
        xpath = "//th[text() = 'Spool Name']"
        self.assertIsNotNone(login_page.webdriver.find_element_by_xpath(xpath))



if __name__ == "__main__":
    unittest.main()

The problem is that I get this error: http://puu.sh/9JgRd/e61f5acec3.png and I'm not sure why I cannot call login method. I have reference to LoginPage object but failure happens exactly here.

1 Answer 1

2

Your problem is not that you can't call login(), but that self.retrieve_username_field returns None and thus does not have a send_keys method. That's exactly what the error you get is telling you.

Sign up to request clarification or add additional context in comments.

2 Comments

Okay, but what is wrong with the code then? I inserted print statements and webdriver.current_url returns correct url. print self.webdriver returns an object not None. And the method is correct because it would throw non-existant method error. Also, the name of the input field is correct. I added implicit wait but it does not work, it returns this error immediately even though the implicit wait is before the property's call.
Omg...forgot a return :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.