class SearchTests(unittest.TestCase): log = cl.customLogger(logging.DEBUG) @pytest.fixture(autouse=True) def objectSetup(self, oneTimeSetUp): self.sp = productSearch(self.driver) self.ts = TestStatus(self.driver) self.nav = NavigationPage(self.driver) @pytest.mark.run(order=1) @data(*getCSVData("textSearchSuccessful.csv")) @unpack def test_searchByNumSuccessful(self, text, numindatabase): self.log.info("Test successful text search on the home page") self.nav.backToHomePage() self.sp.searchProductsByText(text) result = self.sp.searchSuccesfulByNum(numindatabase) assert result == True @pytest.mark.run(order=2) @data(*getCSVData("textSearchByNum.csv")) @unpack def test_searchByTextSuccessful(self, text): self.log.info("Test successful text search on the home page") self.nav.backToHomePage() self.sp.searchProductsByText(text) result = self.sp.searchSuccessfulByText(text) assert result == True @pytest.mark.run(order=3) @data(*getCSVData("textSearchFailed.csv")) @unpack def test_searchByTextFailed(self,text): self.log.info("Test failed text search on the home page") self.nav.backToHomePage() self.sp.searchProductsByText(text) result = self.sp.searchFailed() assert result == True self.ts.markFinal("test_searchByTextFailed", result, "Text search on the home page verification SUCCESSED")
class FiltersPage(BasePage): log = cl.customLogger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver self.nav = NavigationPage(driver) #Loctors _clothes_page = "//a[@href='http://localhost/prestashop/3-clothes']" #by xpath _men_page = '//ul[@class="category-sub-menu"]//a[contains(text(),"Men")]' #byXpath _man_collapse_menu = '//div[@id="left-column"]//ul[@class="category-sub-menu"]/li[1]/div[1]]' #byXpath _woman_page = '//ul[@class="category-sub-menu"]//a[@href="http://localhost/prestashop/5-women"]' #byXpath _woman_collapse_menu = '//div[@id="left-column"]//ul[@class="category-sub-menu"]/li[2]/div[1]' #byXpath _woman_collapse_menu_bluzki = '//ul[@class="category-sub-menu"]/li[2]//ul[@class="category-sub-menu"]//a[contains(text(),"Bluzki")]' # clothes #sizes: _size_S = '//div[@id="search_filters"]/section[2]/ul/li[1]//span[@class="custom-checkbox"]' _size_M = '//div[@id="search_filters"]/section[2]/ul/li[2]//span[@class="custom-checkbox"]' _size_L = '//div[@id="search_filters"]/section[2]/ul/li[3]//span[@class="custom-checkbox"]' _size_XL = '//div[@id="search_filters"]/section[2]/ul/li[4]//span[@class="custom-checkbox"]' #colors: _white_color = '//div[@id="search_filters"]/section[3]/ul/li[1]//span[@class="custom-checkbox"]/input' _black_color = '//div[@id="search_filters"]/section[3]/ul/li[2]//span[@class="custom-checkbox"]/input' #prices: _price_cat1 = '//div[@id="search_filters"]/section[4]/ul/li[1]//span[@class="custom-checkbox"]' _price_cat2 = '//div[@id="search_filters"]/section[4]/ul/li[2]//span[@class="custom-checkbox"]' _price_cat3 = '//div[@id="search_filters"]/section[4]/ul/li[3]//span[@class="custom-checkbox"]' _price_cat4 = '//div[@id="search_filters"]/section[4]/ul/li[4]//span[@class="custom-checkbox"]' def goToMenPageSuccessful(self): self.nav.goToClothesPage() self.elementClick(locator=self._men_page, locatorType='xpath') self.waitForElement( locator= '//div[@class="block-category card card-block hidden-sm-down"]/h1[contains(text(), "Men")]', locatorType='xpath') result = self.isElementPresent( locator= '//div[@class="block-category card card-block hidden-sm-down"]/h1[contains(text(), "Men")]', locatorType='xpath') return result def clothesWomenBluzkiPage(self): self.waitForElement( locator= "//div[@id='js-product-list']/div[@class='products row']/article[1]" ) products = self.driver.find_elements( By.XPATH, "//div[@id='js-product-list']/div[@class='products row']//h1[@class='h3 product-title']/a" ) for el in products: product = el.text if 'Bluzka' not in product: return False return True def clothesPagehoverOverMenu(self): self.nav.backToHomePage() element = self.driver.find_element(By.XPATH, self._clothes_page) actions = ActionChains(self.driver) actions.move_to_element(element).perform() self.waitForElement(locator="//ul[@id='top-menu']/li[1]/div", locatorType="xpath") self.elementClick( locator= "//ul[@id='top-menu']/li[1]/div/ul/li[2]//a[contains(text(),'Bluzki')]", locatorType="xpath") def collapseMenuWomenBlouse(self): self.nav.goToClothesPage() self.waitForElement(locator=self._woman_collapse_menu, locatorType="xpath") self.elementClick(locator=self._woman_collapse_menu, locatorType="xpath") self.waitForElement(locator=self._woman_collapse_menu_bluzki, locatorType='xpath') self.elementClick(locator=self._woman_collapse_menu_bluzki, locatorType='xpath') def multipleFiltersClick(self): # Clicks on the color and size clothes self.nav.goToClothesPage() self.driver.execute_script("window.scrollBy(0, -300);") self.waitForElement(locator='search_filters') self.elementClick(locator=self._size_M, locatorType='xpath') time.sleep(2) self.elementClick(locator=self._black_color, locatorType='xpath') time.sleep(2) def multipleFiltersSuccessful(self): # Checks if selected products are the same as products in database products = [] text_list = [] product_list = self.driver.find_elements( By.XPATH, "//div[@class='products row']/article//h1[@class='h3 product-title']/a" ) for product in product_list: hr = product.text text_list.append(hr.lower()) file = open("product_list_black_m.txt", "r", encoding="utf-8") product_list_database = file.readlines() for line in product_list_database: el = line.rstrip() products.append(el.lower()) for line in products: if line not in text_list: return False return True
class AccountTests(unittest.TestCase): log = cl.customLogger(logging.DEBUG) @pytest.fixture(autouse=True) def objectSetup(self, oneTimeSetUp): self.ap = AccountPage(self.driver) self.ts = TestStatus(self.driver) self.nav = NavigationPage(self.driver) # @pytest.mark.run(order=1) # def test_registerFormElementsValidation(self): # self.log.info("Validation of elements of a customer registration form successful") # result = self.ap.registerFormElementsValidation() # assert result == True @pytest.mark.run(order=2) def test_createNewAccountFailedEmail(self): self.nav.backToHomePage() self.log.info( "Created a new customer account unsuccessful by providing an invalid email address" ) result = self.ap.createNewAccountFailed(firstname="Jan", lastname="Kowalski", email="*****@*****.**", password="******") assert result == True @pytest.mark.run(order=3) def test_createNewAccountFailedFirstname(self): self.nav.backToHomePage() email = "test" + str(round(time.time() * 1000)) + "@test.com" self.log.info( "Created a new customer account unsuccessful by providing an invalid firstname" ) result = self.ap.createNewAccountFailed(firstname="123@$", lastname="Kowalski", email=email, password="******") assert result == True @pytest.mark.run(order=4) def test_createNewAccountFailedLastname(self): self.nav.backToHomePage() email = "test" + str(round(time.time() * 1000)) + "@test.com" self.log.info( "Created a new customer account unsuccessful by providing an invalid firstname" ) result = self.ap.createNewAccountFailed(firstname="Jan", lastname="$@23", email=email, password="******") assert result == True @pytest.mark.run(order=5) def test_createNewAccountSuccessful(self): self.nav.backToHomePage() self.log.info("Created a new customer account successful") email = "test" + str(round(time.time() * 1000)) + "@test.com" result = self.ap.createNewAccountSuccessful(firstname="Jan", lastname="Kowalski", email=email, password="******") assert result == True self.ts.markFinal( "test_createNewAccountSuccessful", result, "Created a new customer account successful " "verification SUCCESSED")
class CheckoutTests(unittest.TestCase): log = cl.customLogger(logging.DEBUG) @pytest.fixture(autouse=True) def objectSetup(self, oneTimeSetUp): self.chp = CheckoutPage(self.driver) self.lp = LoginPage(self.driver) self.ts = TestStatus(self.driver) self.nav = NavigationPage(self.driver) self.sd = SeleniumDriver(self.driver) @pytest.mark.run(order=1) def test_checkoutGuestFormPersonalInformationSuccessful(self): self.log.info("Personal Information form for guest client successed") email = email = "test" + str(round(time.time() * 1000)) + "@test.com" result = self.chp.checkoutGuestFormPersonalInformationSuccessful( firstname="Adam", lastname="Kowalski", email=email, password="******") assert result == True @pytest.mark.run(order=2) def test_checkoutGuestFormPersonalInformationFailed(self): self.log.info( "Personal Information form for guest client failed due to wrong email" ) self.nav.clearCartAndGoToMainPage() self.lp.logOut() result = self.chp.checkoutGuestFormPersonalInformationFailed( firstname="Adam", lastname="Kowalski", email="*****@*****.**", password="******") assert result == True @pytest.mark.run(order=3) def test_addressFormSuccessful(self): self.log.info("Address form for guest client successful") self.nav.clearCartAndGoToMainPage() self.lp.logOut() email = email = "test" + str(round(time.time() * 1000)) + "@test.com" result = self.chp.addressFormSuccessful(firstname="Adam", lastname="Kowalski", email=email, password="******", address="Testowa 1/2", postcode="00-000", city="Warszawa", phone="500500500") assert result == True @pytest.mark.run(order=4) def test_addressFormFailed(self): self.log.info( "Address form for guest client failed due to wrong postcode") self.nav.clearCartAndGoToMainPage() self.lp.logOut() email = email = "test" + str(round(time.time() * 1000)) + "@test.com" result = self.chp.addressFormFailed(firstname="Adam", lastname="Kowalski", email=email, password="******", address="Testowa 1/2", postcode="00", city="Warszawa", phone="500500500") assert result == True @pytest.mark.run(order=5) def test_addressFormFailed2(self): self.log.info( "Address form for guest client failed due to wrong phone number") self.nav.clearCartAndGoToMainPage() self.lp.logOut() email = email = "test" + str(round(time.time() * 1000)) + "@test.com" result = self.chp.addressFormFailed(firstname="Adam", lastname="Kowalski", email=email, password="******", address="Testowa 1/2", postcode="00-000", city="Warszawa", phone="abc") assert result == True @pytest.mark.run(order=6) def test_deliverySuccessed(self): self.log.info("Delivery form successed") self.nav.clearCartAndGoToMainPage() self.lp.logOut() email = email = "test" + str(round(time.time() * 1000)) + "@test.com" result = self.chp.deliverySuccessed(firstname="Adam", lastname="Kowalski", email=email, password="******", address="Testowa 1/2", postcode="00-000", city="Warszawa", phone="500500500") assert result == True @pytest.mark.run(order=7) def test_paymentConditionsAcceptanceVerification(self): self.log.info("Payment conditions acceptance verification successful") self.nav.clearCartAndGoToMainPage() self.lp.logOut() email = email = "test" + str(round(time.time() * 1000)) + "@test.com" result = self.chp.paymentConditionsAcceptanceVerification( firstname="Adam", lastname="Kowalski", email=email, password="******", address="Testowa 1/2", postcode="00-000", city="Warszawa", phone="500500500") assert result == True @pytest.mark.run(order=8) def test_paymentSuccessed(self): self.log.info("Address form for guest client successful") self.nav.clearCartAndGoToMainPage() self.lp.logOut() email = email = "test" + str(round(time.time() * 1000)) + "@test.com" result = self.chp.paymentSuccessed(firstname="Adam", lastname="Kowalski", email=email, password="******", address="Testowa 1/2", postcode="00-000", city="Warszawa", phone="500500500") assert result == True @pytest.mark.run(order=9) def test_personalInfVerificationLoggedInClient(self): self.log.info( "Personal information form for logged in client verification successful" ) self.nav.clearCartAndGoToMainPage() self.lp.logOut() result = self.chp.personalInfVerificationLoggedInClient( username="******", email="*****@*****.**", password="******") assert result == True @pytest.mark.run(order=10) def test_addressVerificationLoggedInClient(self): self.log.info("Address form for logged in client successful") self.nav.backToHomePage() self.lp.logOut() address = "Ewa Kowalska\nul. Testowa\n00-000 Warszawa\nPolska\n600600600" result = self.chp.addressVerificationLoggedInClient( address=address, email="*****@*****.**", password="******") assert result == True @pytest.mark.run(order=10) def test_addNewAddressLoggedInClient(self): self.log.info("Add address form for logged in client successful") self.nav.backToHomePage() self.lp.logOut() address = "Testowa" + str(round(time.time() * 1000)) + "/2" result = self.chp.addNewAddressLoggedinClient(email="*****@*****.**", password="******", address=address, postcode="00-000", city="Warszawa", phone="600600600") assert result == True self.ts.markFinal( "test_addNewAddressLoggedinClient", result, "Add address form for logged in client successful" "verification SUCCESSED")