コード例 #1
0
class TestPhpTravelPage:
    @pytest.fixture(scope='function', autouse=True)
    def app_setup(self):

        self.webdriver = webdriver.Chrome()
        self.home_page = HomePage(self.webdriver)
        self.login_page = Login(self.webdriver)
        self.landing_page_hotel = LandingPageHotel(self.webdriver)
        self.valid_credentials = conf_reader.get_user_credentials()
        self.search_result_page = SearchResultPage(self.webdriver)

        yield
        self.webdriver.quit()

    @pytest.fixture(scope='function')
    def valid_login(self):
        """
        A fixture method to execute the common steps till performing login
        :return:
        """
        self.home_page.open_webpage()
        self.home_page.open_login_page()
        self.login_page.user_login(self.valid_credentials.email,
                                   self.valid_credentials.password)

    def test_home_page_pvt(self):
        self.home_page.open_webpage()
        self.home_page.implicitly_wait(10)
        assert self.home_page.is_loaded(self.home_page.key_locators)

    def test_landing_page_pvt(self, valid_login):
        assert self.landing_page_hotel.is_loaded(
            self.landing_page_hotel.key_locators)
コード例 #2
0
class TestAuthentication:
    @pytest.fixture(scope='function', autouse=True)
    def setup(self):
        """
        This fixture holds the common setup steps required to Login to the application
        returns: Home page of the application for authenticated users
        """
        self.webdriver = webdriver.Chrome()
        self.base_page = BasePage(self.webdriver)
        self.home_page = HomePage(self.webdriver)
        self.login_page = Login(self.webdriver)
        self.search_result_page = SearchResultPage(self.webdriver)
        self.valid_credentials = conf_reader.get_user_credentials()
        self.landing_page_hotel = LandingPageHotel(self.webdriver)
        self.home_page.open_login_page()

        yield
        self.webdriver.quit()

    def test_valid_user_login(self):
        """
        This method enters the correct credentials for a user in the application and
        :returns: Homepage of application after successful login.

        We verify this by asserting the presence of User's Image icon

        """

        self.login_page.user_login(self.valid_credentials.email,
                                   self.valid_credentials.password)

        assert self.landing_page_hotel.is_loaded(
            self.landing_page_hotel.key_locators)

    @pytest.mark.parametrize("user_name, password",
                             [('*****@*****.**', '********'),
                              ('*****@*****.**', 'demouser'),
                              ('', ''), ('*****@*****.**', '        ')])
    def test_invalid_login_scenarios(self, user_name, password):
        """
        Test- 1
        This test checks for all the invalid username/email and password combination by taking param
        from above
            Case 1 : Valid username and invalid password
            Case 2 : Invalid username and valid password
            Case 3 : Blank Username and Password
            Case 4 : Valid Username and Spaces as password

        returns: An error message indicating incorrect credentials
        """

        self.login_page.user_login_failed(user_name, password)
        assert self.login_page.get_error_message_from_alert(
        ) == "Invalid Email or Password"
コード例 #3
0
class TestTours:
    @pytest.fixture(scope='function', autouse=True)
    def setup(self):
        """Tours
        This fixture holds the common setup steps required to Login to the application
        returns: Home page of the application for authenticated users
        """
        self.webdriver = webdriver.Chrome()
        self.home_page = HomePage(self.webdriver)
        self.login_page = Login(self.webdriver)
        self.search_result_page = SearchResultPage(self.webdriver)
        self.valid_credentials = conf_reader.get_user_credentials()
        self.landing_page_tours = LandingPageTour(self.webdriver)
        self.home_page.open_login_page()
        self.login_page.user_login(self.valid_credentials.email,
                                   self.valid_credentials.password)
        self.landing_page_tours.click_tour_button()

        yield
        self.webdriver.quit()

    def test_error_handling_for_garbage_values_in_tours_field(self):
        """
        Test- 7:
        Action : User tries to search a tour by giving garbage input in searchbox
        Returns: An error is displayed
        Asserted : That the correct error message is displayed

        """
        invalid_str = 'asdasdfadfaf'
        time.sleep(5)
        self.landing_page_tours.enter_garbage_value_to_tour_field(invalid_str)

        assert self.webdriver.find_element(By.XPATH, self.landing_page_tours._err_srch_box_tours) \
                   .text == 'No matches found'

    def test_error_thrown_on_exceeding_max_adult_tourists(self):
        """
        Test- 8
        Action: User searches with valid guests , and then makes the change in the URL
        return: There should be an error displayed for exceeding max guests
        Asserted: The correct error message is displayed
        """
        error_message = 'Maximum Number of Adults exceeded for this tour'
        self.webdriver.get(
            "https://www.phptravels.net/tours/united-arab-emirates/dubai/Sheraton"
            "-Trip?date=10/08/2019&adults=7")

        error_text = self.webdriver.find_element(
            By.XPATH, self.landing_page_tours._err_max_tourists_exceeded).text
        error_text = str(error_text).lstrip().rstrip()

        assert error_text == error_message
コード例 #4
0
class TestHotel:
    @pytest.fixture(scope='function', autouse=True)
    def setup(self):
        """
        This fixture holds the common setup steps required to Login to the application
        returns: Home page of the application for authenticated users
        """
        self.webdriver = webdriver.Chrome()
        self.base_page = BasePage(self.webdriver)
        self.home_page = HomePage(self.webdriver)
        self.login_page = Login(self.webdriver)
        self.search_result_page = SearchResultPage(self.webdriver)
        self.valid_credentials = conf_reader.get_user_credentials()
        self.landing_page_hotel = LandingPageHotel(self.webdriver)
        self.home_page.open_login_page()
        self.login_page.user_login(self.valid_credentials.email,
                                   self.valid_credentials.password)
        self.webdriver.get("https://www.phptravels.net/m-thhotels")

        yield
        self.webdriver.quit()

    def test_user_can_not_search_with_blank_hotel_or_city_name(
            self, data_trip_with_out_hotel_name):
        """
        Test- 2
        This test ensures the mandatory details of city/hotel name are compulsorily given by users.

        This test will fail , but that indicates that user can perform search with blank hotel name

        """
        self.landing_page_hotel.search_and_select_city(
            data_trip_with_out_hotel_name.hotel_name)
        self.landing_page_hotel.select_checkin_and_checkout_dates(
            data_trip_with_out_hotel_name.check_in_date,
            data_trip_with_out_hotel_name.check_out_date)
        self.landing_page_hotel.click_search_button()

        assert not self.search_result_page.is_loaded(
            self.search_result_page.key_locators)
        """assert here should have been on The Search button is not clickable or 
        that there is an error message.
        but since that demands a different implementation, 
        My assertion is for search result page not loaded"""

    def test_checkout_date_can_not_be_prior_to_checkin_date(
            self, data_check_out_before_check_in_details):
        """
        Test- 3: Assuming that user is entering a Checkout date which is prior to checkin date
        (which is possible as per current implementation) for hotel search ,
        This test will fail to indicate that the input provided is incorrect

        """
        self.landing_page_hotel.search_and_select_city(
            data_check_out_before_check_in_details.hotel_name)
        self.landing_page_hotel.select_checkin_and_checkout_dates(
            data_check_out_before_check_in_details.check_in_date,
            data_check_out_before_check_in_details.check_out_date)

        assert data_check_out_before_check_in_details.check_in_date < data_check_out_before_check_in_details.check_out_date

    def test_number_of_guests_can_not_be_zero_or_less(self,
                                                      data_number_of_guests):
        """
        Test- 4
        The number of guests can not be zero or less and thus negative values should not be allowed
        This test will fail if User gives 0 as input for number of guests

        We are currently giving 0 as input for guests , thus this will fail
        """
        adult_guests = 0
        child_guests = 0
        self.landing_page_hotel.search_and_select_city(
            data_number_of_guests.hotel_name)
        self.landing_page_hotel.select_checkin_and_checkout_dates(
            data_number_of_guests.check_in_date,
            data_number_of_guests.check_out_date)
        self.landing_page_hotel.enter_number_of_guests(adult_guests,
                                                       child_guests)

        assert self.landing_page_hotel.get_number_of_guests() > 0

    def test_number_of_guests_can_not_exceed_five(self, setup,
                                                  data_number_of_guests):
        """
        Test- 5
        The number of guests , if more than 5 would need a bulk booking ,
        this is a scenario which is more near to real life booking by a customer.
        (Wee can define our own upper limit , idea is big numbers as 100000 should not be allowed)
        """
        adult_guests = 10
        child_guests = 0
        self.landing_page_hotel.search_and_select_city(
            data_number_of_guests.hotel_name)
        self.landing_page_hotel.select_checkin_and_checkout_dates(
            data_number_of_guests.check_in_date,
            data_number_of_guests.check_out_date)
        self.landing_page_hotel.enter_number_of_guests(adult_guests,
                                                       child_guests)

        assert self.landing_page_hotel.get_number_of_guests() <= 5

    def test_checkin_date_can_not_be_in_past(self, setup,
                                             data_number_of_guests):
        """
        Test- 6
        There can not be a hotel search for a past date. If a user is trying to make such a booking,
        This should give user an error
        """

        self.landing_page_hotel.search_and_select_city(
            data_number_of_guests.hotel_name)
        self.landing_page_hotel.select_checkin_and_checkout_dates(
            data_number_of_guests.check_in_date,
            data_number_of_guests.check_out_date)
        todays_date = date.today()
        required_format_today = todays_date.strftime("%d/%m/%Y")

        assert required_format_today > data_number_of_guests.check_in_date
        """The assert should be that the search button is not clickable,