0

I am trying to implement a POM(Page Object Model) in PyCharm by creating packages named PageObjects and testCases. However, as soon as I run my test class in Python, I get

ImportError: No Module named pageObjects.LoginPage

Screenshot of my project structure

enter image description here

AutoTest.py

import unittest
import HtmlTestRunner
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import sys
sys.path.append("C:\Users\lukegoh\Desktop\Python Projects\SoftwareAutomationTesting")
from pageObjects.LoginPage import LoginPage



class AutoTest(unittest.TestCase):
    baseURL = "https://10.2.5.215:33000/viewTopUpRequest"
    username = "ezltest2svc"
    password = "Password123!"
    driver = webdriver.Chrome()

    @classmethod
    def setUpClass(cls):
        cls.driver.get(cls.baseURL)
        cls.driver.maximize_window()
        cls.driver.implicitly_wait(10)


    def test_login(self):
        lp = LoginPage(self.driver)
        lp.setUsername(self.username)
        lp.setPassword(self.password)
        lp.clickLogin()
        lp.clickUtil()



    @classmethod
    def tearDownClass(cls):
        cls.driver.close()
        print("Test Completed")


if __name__ == '__main__':
    unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='C:/Users/lukegoh/Desktop/Python Projects/SoftwareAutomationTesting/reports'))

LoginPage.py

class LoginPage:

    textbox_username_name="username"
    textbox_password_name="password"
    button_login_xpath="//button[contains(text(),'Login')]"
    utilityTopUp_xpath ="//div[@id='wrapper']/div/ul/li[9]/a"

    def __init__(self,driver):
        self.driver=driver


    def setUsername(self,username):
        self.driver.find_element_by_name(self.textbox_username_name).send_keys(username)


    def setPassword(self, password):
        self.driver.find_element_by_name(self.textbox_password_name).send_keys(password)


    def clickLogin(self):
        self.driver.find_element_by_xpath(self.button_login_xpath).click()

    def clickutil(self):
        self.driver.find_element_by_xpath(self.utilityTopUp_xpath).click()

Is there a way to solve this?

TechGeek49
  • 476
  • 1
  • 7
  • 24

1 Answers1

1

I have already solved it by adding __init__.py empty file inside the packages I've created.

Link can be found here: Python - Module Not Found

TechGeek49
  • 476
  • 1
  • 7
  • 24