diff --git a/chromedriver.exe b/chromedriver.exe new file mode 100644 index 0000000..f74d9fe Binary files /dev/null and b/chromedriver.exe differ diff --git a/terminal_wyniki b/terminal_wyniki new file mode 100644 index 0000000..0001275 --- /dev/null +++ b/terminal_wyniki @@ -0,0 +1,70 @@ +Windows PowerShell +Copyright (C) Microsoft Corporation. All rights reserved. + +PS C:\Users\tomek_user\Desktop\python-lodz\selenium-workshop> py .\check.py + +DevTools listening on ws://127.0.0.1:51121/devtools/browser/ca4c4b0c-1ce1-4e0e-8c38-7aa95ae0dcc9 +[34020:14404:1207/221334.461:ERROR:shader_disk_cache.cc(257)] Failed to create shader cache entry: -2 +W nowym oknie Chrome powinna załadować się strona python.org + +PS C:\Users\tomek_user\Desktop\python-lodz\selenium-workshop> py .\zadanie1.py + +DevTools listening on ws://127.0.0.1:51953/devtools/browser/7ca5b9d4-2ef6-40dd-9a60-0aab21b9622a +Nastepny URL: https://breadcrumbscollector.tech/pl/selenium/2223.html +. +---------------------------------------------------------------------- +Ran 1 test in 7.152s + +OK + +PS C:\Users\tomek_user\Desktop\python-lodz\selenium-workshop> py .\zadanie2.py + +DevTools listening on ws://127.0.0.1:52779/devtools/browser/32bc0d6f-4aa6-48e2-ab87-b563a054989b +. +---------------------------------------------------------------------- +Ran 1 test in 7.810s + +OK + +PS C:\Users\tomek_user\Desktop\python-lodz\selenium-workshop> py .\zadanie3.py + +DevTools listening on ws://127.0.0.1:53160/devtools/browser/56ac7dbe-6c3e-4b81-bd74-bfb945715483 +[56084:45688:1207/223516.299:ERROR:shader_disk_cache.cc(257)] Failed to create shader cache entry: -2 +[56084:45688:1207/223520.346:ERROR:shader_disk_cache.cc(257)] Failed to create shader cache entry: -2 +Found accommodation: WestHouse Hotel New York +. +---------------------------------------------------------------------- +Ran 1 test in 13.605s + +OK + +PS C:\Users\tomek_user\Desktop\python-lodz\selenium-workshop> py .\zadanie4.py + +DevTools listening on ws://127.0.0.1:53571/devtools/browser/8fcf201d-05b1-4cca-b59b-6d9b868c6875 +[49268:1624:1207/223926.566:ERROR:shader_disk_cache.cc(257)] Failed to create shader cache entry: -2 +Dostępność obiektów o 3 gwiazdkach w marcu 2019: : True +W weekend 15-16. grudnia na Manhattanie nie ma więcej niż 10 dostępnych ofert w najniższym przedziale +cenowym: : True +. +---------------------------------------------------------------------- +Ran 1 test in 22.218s + +OK + +PS C:\Users\tomek_user\Desktop\python-lodz\selenium-workshop> py .\zadanie4.py + +DevTools listening on ws://127.0.0.1:55455/devtools/browser/cac1f74b-b6ff-4dff-8bcb-0faca6eb7901 +[51892:81628:1210/211421.800:ERROR:shader_disk_cache.cc(257)] Failed to create shader cache entry: -2 +[51892:81628:1210/211422.385:ERROR:shader_disk_cache.cc(257)] Failed to create shader cache entry: -2 +[51892:81628:1210/211428.248:ERROR:shader_disk_cache.cc(257)] Failed to create shader cache entry: -2 +Dostępność obiektów o 3 gwiazdkach w marcu 2019: True + +DevTools listening on ws://127.0.0.1:55551/devtools/browser/c1296a78-47d1-449b-a08a-043bc1439904 +[61084:19276:1210/211443.156:ERROR:shader_disk_cache.cc(257)] Failed to create shader cache entry: -2 +[61084:19276:1210/211453.981:ERROR:shader_disk_cache.cc(257)] Failed to create shader cache entry: -2 +W weekend 15-16. grudnia na Manhattanie nie ma więcej niż 10 dostępnych ofert w najniższym przedziale cenowym: True +. +---------------------------------------------------------------------- +Ran 1 test in 48.414s + +OK \ No newline at end of file diff --git a/zadanie1.py b/zadanie1.py index eee5f8f..8ca4526 100644 --- a/zadanie1.py +++ b/zadanie1.py @@ -1,5 +1,7 @@ import unittest +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import Select from selenium import webdriver from selenium.webdriver.support.ui import Select @@ -24,7 +26,16 @@ def tearDown(self): def test_exercise(self): # miejsce na Twoje rozwiązanie - + self.driver.get('https://breadcrumbscollector.tech/pl/selenium/01.html') + self.driver.find_element(By.CLASS_NAME, 'de').click() + self.driver.find_element(By.CLASS_NAME, 'spa').click() + self.driver.find_element(By.CLASS_NAME, 'ci').click() + self.driver.find_element(By.CLASS_NAME, 'to').click() + self.driver.find_element_by_id('lang').click() + + #self.driver.find_element_by_id('lang').send_keys('h') + select = Select(self.driver.find_element_by_id('lang')) + select.select_by_visible_text('hiszpański') next_url = self.driver.switch_to.alert.text self.driver.switch_to.alert.accept() print(f'Nastepny URL: {next_url}') diff --git a/zadanie2.py b/zadanie2.py index e9c435a..15d2dba 100644 --- a/zadanie2.py +++ b/zadanie2.py @@ -29,11 +29,41 @@ def setUp(self): def tearDown(self): self.driver.quit() - + # https://www.paste.org/96245 - próba wykonania drag and drop bez sukcesu. + # Element jest łapany i przeciągany ale nie jest upuszczany def test_exercise(self): - self.driver.get('Z POPRZEDNIEGO ZADANIA') + self.driver.get('https://breadcrumbscollector.tech/pl/selenium/2223.html') - assert self.driver.find_element_by_id('recipe').text == 'Gotowe!' + recipe = self.driver.find_element_by_id('recipe').text + + while(not recipe in 'Gotowe!'): + action_chains = ActionChains(self.driver) + if recipe == 'Gotuj na wolnym ogniu': + self.driver.find_element_by_css_selector('#heating-control > label:nth-child(1)').click() + recipe = self.driver.find_element_by_id('recipe').text + continue + elif recipe == 'Gotuj na dużym ogniu': + self.driver.find_element_by_css_selector('#heating-control > label:nth-child(3)').click() + recipe = self.driver.find_element_by_id('recipe').text + continue + elif recipe == 'Wrzuć ziemniaka': + action_chains.double_click(self.driver.find_element_by_id('potato')).perform() + recipe = self.driver.find_element_by_id('recipe').text + continue + elif recipe == 'Wrzuć marchewkę': + action_chains.double_click(self.driver.find_element_by_id('carrot')).perform() + recipe = self.driver.find_element_by_id('recipe').text + continue + elif recipe == 'Wrzuć sałatę': + action_chains.double_click(self.driver.find_element_by_id('lettuce')).perform() + recipe = self.driver.find_element_by_id('recipe').text + continue + elif recipe == 'Wrzuć mięso': + action_chains.double_click(self.driver.find_element_by_id('meat')).perform() + recipe = self.driver.find_element_by_id('recipe').text + continue + + assert self.driver.find_element_by_id('recipe').text == 'Gotowe!' if __name__ == "__main__": diff --git a/zadanie3.py b/zadanie3.py index 616ad09..5977d30 100644 --- a/zadanie3.py +++ b/zadanie3.py @@ -16,12 +16,21 @@ class WorkshopTests(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() + self.driver.get('https://booking.com') def tearDown(self): self.driver.quit() def test_exercise(self): - self.driver.get('https://booking.com') + self.driver.find_element_by_id('ss').send_keys('Nowy Jork Manhattan') + self.driver.find_element_by_class_name('sb-date-field__icon').click() + self.driver.find_element_by_css_selector('#frm > div.xp__fieldset.accommodation > div.xp__dates.xp__group > div.xp-calendar > div > div > div.bui-calendar__content > div:nth-child(2) > table > tbody > tr:nth-child(2) > td:nth-child(7)').click() + self.driver.find_element_by_css_selector('#frm > div.xp__fieldset.accommodation > div.xp__dates.xp__group > div.xp-calendar > div > div > div.bui-calendar__content > div:nth-child(2) > table > tbody > tr:nth-child(3) > td:nth-child(5)').click() + self.driver.find_element_by_class_name('sb-searchbox__button').click() + self.driver.find_element_by_partial_link_text('od najniższej').click() #przy założeniu strony w wersji polskojęzycznej + + print('Found accommodation: ' + WebDriverWait(self.driver, 9).until(expected_conditions.visibility_of_element_located( + (By.CSS_SELECTOR, '#hotellist_inner > div:nth-child(1) > div.sr_item_content.sr_item_content_slider_wrapper > div.sr_property_block_main_row > div.sr_item_main_block > h3 > a > span.sr-hotel__name'))).text) if __name__ == "__main__": diff --git a/zadanie4.py b/zadanie4.py index 9f866cd..c059da1 100644 --- a/zadanie4.py +++ b/zadanie4.py @@ -1,7 +1,9 @@ import unittest from selenium import webdriver - +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions class WorkshopTests(unittest.TestCase): """ @@ -11,22 +13,107 @@ class WorkshopTests(unittest.TestCase): - filtrów ilości gwiazdek na stronie wyników Korzystając z gotowych komponentów, napisz dwa scenariusze (metody) testowe: - - sprawdzający dostępność obiektów o 3 gwiazdkach w marcu 2018 - - sprawdzający że w weekend 15-16. grudnia na Mahattanie nie ma więcej niż 10 dostępnych ofert w najniższym przedziale cenowym + - sprawdzający dostępność obiektów o 3 gwiazdkach w marcu 2019 + - sprawdzający że w weekend 15-16. grudnia na Manhattanie nie ma więcej niż 10 dostępnych ofert w najniższym przedziale cenowym Page objects: https://selenium-python.readthedocs.io/page-objects.html """ + _InputField = 'ss' + _ValueToSearch = 'Manhattan, Nowy Jork' + _DateField = 'sb-date-field__icon' + _DayInCalendarFrom = '#frm > div.xp__fieldset.accommodation > div.xp__dates.xp__group > div.xp-calendar > div > div > div.bui-calendar__content > div:nth-child(2) > table > tbody > tr:nth-child(2) > td:nth-child(5)' + _DayInCalendarTo = '#frm > div.xp__fieldset.accommodation > div.xp__dates.xp__group > div.xp-calendar > div > div > div.bui-calendar__content > div:nth-child(2) > table > tbody > tr:nth-child(6) > td:nth-child(7)' + _SearchButton = 'sb-searchbox__button' + _PartNameLinkToSortByPrice = 'od najniższej' + _CheapestAccomodation = '#hotellist_inner > div:nth-child(1) > div.sr_item_content.sr_item_content_slider_wrapper > div.sr_property_block_main_row > div.sr_item_main_block > h3 > a > span.sr-hotel__name' + #_FilterByPriceInCheckBox = '0 zł - ' + _FilterByLowestPrice = '#filter_price > div.filteroptions > a:nth-child(1)' + _FilterByStarInCheckBox = '3 gwiazdki' + _MonthInCalendar = 'marzec 2019' + _PlaceDateInCalendar = '#frm > div.xp__fieldset.accommodation > div.xp__dates.xp__group > div.xp-calendar > div > div > div.bui-calendar__content > div:nth-child(2) > div' + _ArrowToNextMonthInCalendar = '#frm > div.xp__fieldset.accommodation > div.xp__dates.xp__group > div.xp-calendar > div > div > div.bui-calendar__control.bui-calendar__control--next > svg' + _15December = '#frm > div.xp__fieldset.accommodation > div.xp__dates.xp__group > div.xp-calendar > div > div > div.bui-calendar__content > div:nth-child(1) > table > tbody > tr:nth-child(4) > td:nth-child(6)' + _16December = '#frm > div.xp__fieldset.accommodation > div.xp__dates.xp__group > div.xp-calendar > div > div > div.bui-calendar__content > div:nth-child(1) > table > tbody > tr:nth-child(4) > td:nth-child(7)' + _ObjectsOnSearchList = 'sr_item_new' + _check1 = 'Dostępność obiektów o 3 gwiazdkach w marcu 2019' + _check2 = 'W weekend 15-16. grudnia na Manhattanie nie ma więcej niż 10 dostępnych ofert w najniższym przedziale cenowym' + _NoMoreThan10 = 'NoMoreThan10' + _AvailabilityOf3Star = 'AvailabilityOf3Star' + + def test_exercise(self): + #sprawdzający dostępność obiektów o 3 gwiazdkach w marcu 2019 + self.CheckTheAvailabilityOf_3_StarFacilitiesInMarch2019() - def setUp(self): - self.driver = webdriver.Chrome() + #sprawdzający że w weekend 15-16. grudnia na Manhattanie nie ma więcej niż 10 dostępnych ofert w najniższym przedziale cenowym + self.ThereNoMoreThan_10_AvailableOffersInTheLowestPriceRangeIn15And16December() def tearDown(self): self.driver.quit() - def test_exercise(self): - pass + def inputValueToSearch(self, _InputField, _ValueToSearch): + self.driver.find_element_by_id(_InputField).send_keys(_ValueToSearch) + + def clickOnCalendar(self, _DateField): + self.driver.find_element_by_class_name(_DateField).click() + + def chooseDateInCalendar(self, _DayInCalendarFrom, _DayInCalendarTo): + self.driver.find_element_by_css_selector(_DayInCalendarFrom).click() + self.driver.find_element_by_css_selector(_DayInCalendarTo).click() + + def clickSearchButton(self, _SearchButton): + self.driver.find_element_by_class_name(_SearchButton).click() + + def sortResultsOnPage(self, _PartNameLinkToSortByPrice): + self.driver.find_element_by_partial_link_text(_PartNameLinkToSortByPrice).click() #przy założeniu strony w wersji polskojęzycznej + def chooseCheapestPlace(self, _CheapestAccomodation): + print(WebDriverWait(self.driver, 9).until(expected_conditions.visibility_of_element_located( + (By.CSS_SELECTOR, _CheapestAccomodation))).text) + + def filterByPrice(self, _FilterByLowestPrice): + self.driver.find_element_by_css_selector(_FilterByLowestPrice).click() + + def filterByStar(self, _FilterByStarInCheckBox): + self.driver.find_element_by_partial_link_text(_FilterByStarInCheckBox).click() + + def findMonthInCalendar(self, _MonthInCalendar, _PlaceDateInCalendar, _ArrowToNextMonthInCalendar): + while not _MonthInCalendar in self.driver.find_element_by_css_selector(_PlaceDateInCalendar).text: + self.driver.find_element_by_css_selector(_ArrowToNextMonthInCalendar).click() + return + + def countFoundAccomodation(self, text, _ObjectsOnSearchList, logic): + foundAccommodations = self.driver.find_elements_by_class_name(_ObjectsOnSearchList) + foundAccommodationsLength = len(foundAccommodations) + if ('NoMoreThan10' in logic): + print(str(text + ': {}').format(foundAccommodationsLength > 0 and foundAccommodationsLength < 10)) + assert foundAccommodationsLength > 0 and foundAccommodationsLength < 10 #sprawdzający że w weekend 15-16. grudnia na Manhattanie nie ma więcej niż 10 dostępnych ofert w najniższym przedziale cenowym + elif ('AvailabilityOf3Star' in logic): + print(str(text + ': {}').format(foundAccommodationsLength > 0)) + assert foundAccommodationsLength > 0 #- sprawdzający dostępność obiektów o 3 gwiazdkach w marcu 2019 + else: + assert False + + def ThereNoMoreThan_10_AvailableOffersInTheLowestPriceRangeIn15And16December(self): + self.driver = webdriver.Chrome() + self.driver.get('https://booking.com') + self.inputValueToSearch(self._InputField, self._ValueToSearch) + self.clickOnCalendar(self._DateField) + self.chooseDateInCalendar(self._15December, self._16December) + self.clickSearchButton(self._SearchButton) + self.filterByPrice(self._FilterByLowestPrice) + self.countFoundAccomodation(self._check2, self._ObjectsOnSearchList, self._NoMoreThan10) + + def CheckTheAvailabilityOf_3_StarFacilitiesInMarch2019(self): + self.driver = webdriver.Chrome() + self.driver.get('https://booking.com') + self.inputValueToSearch(self._InputField, self._ValueToSearch) + self.clickOnCalendar(self._DateField) + self.findMonthInCalendar(self._MonthInCalendar, self._PlaceDateInCalendar, self._ArrowToNextMonthInCalendar) + self.chooseDateInCalendar(self._DayInCalendarFrom, self._DayInCalendarTo) + self.clickSearchButton(self._SearchButton) + self.filterByStar(self._FilterByStarInCheckBox) + self.countFoundAccomodation(self._check1, self._ObjectsOnSearchList, self._AvailabilityOf3Star) if __name__ == "__main__": unittest.main()