1

Project structure:

WebTeam
    __init__.py
    BasePage.py
    UIMap.py

Pages:
    __init__.py
    Common.py
    ContactPage.py

test:
    __init__.py
    CompetitorsTest.py
    CreateAnonData.py
    CreateKnownData.py

The code:

import unittest
import time

from selenium                                       import webdriver
from selenium.webdriver.support.ui                  import WebDriverWait
from selenium.webdriver.common.action_chains        import ActionChains
from BasePage                                       import BasePage
from UIMap                                          import tomcat8LoginPage, tomcat8urls, competitors

class test_Competitors(unittest.TestCase, BasePage):

def setup(self):
    self.driver = webdriver.Firefox()
    self.driver.get(tomcat8urls ['loginPageTomcat8'])

def test_Compete(self):
    driver = self.driver
    actions = ActionChains(driver)

    ### Log-in and navigate to Competitors page ###
    self.fill_out_field\
        ("id",
            tomcat8LoginPage ['usernameField'],'username2092')

    self.fill_out_field\
        ("id",
            tomcat8LoginPage['passwordField'],'Password2092')

    self.click\
        ("id",
            tomcat8LoginPage ['loginBtn'])

    driver.get(tomcat8urls ['newUIurl'])

    self. click\
        ("xpath",
            competitors ['inboundMenu'])

This is the latest error I have gotten:

Traceback (most recent call last):
  File "CompetitorsTest.py", line 18, in test_Compete
  driver = self.driver
AttributeError: 'test_Competitors' object has no attribute 'driver'
3

Your setup method should be setUp for unittest. I'm not sure why they decided to name it that way, but that's just how it is.

Since setup is not a keyword it's not getting called, thereby making self.driver throw an AttributeError.

But I did the same thing still not working for me any specific reasons ??

"from YFT_Pages.LogInPage import LogIn from YFT_Pages.CreateAccount import CreateAccount import unittest

class MyTestCase(unittest.TestCase):

@classmethod
def setUp(cls) -> None:
    driver = webdriver.Chrome(executable_path = r"E:\Doc & Sw\chromedriver.exe")

def test_LogIn(self):
    driver = self.driver
    driver.get("http://foottech.4thpointer.in/")

    createAccount = CreateAccount(driver)
    createAccount.user_Name("Shorya Kaushik")
    createAccount.user_Phone("8791517915")
    createAccount.user_Mail("Shorya@Test.com")
    createAccount.user_Password("123")
    createAccount.user_ConfPassword("123")
    createAccount.user_Role("Player")
    createAccount.user_submit()

    login = LogIn(driver)
    login.userMail("shorya@test.com")
    login.userPassword("123")
    login.submit()

@classmethod
def tearDown(cls) -> None:
    cls.driver.close()
    cls.driver.quit()

if name == 'main': unittest.main()

"

| improve this answer | |

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.