Exemple #1
0
def test_2():

        try:  
            # create lib page object  
            obj_lib=LIB()

            # open browser
            browser=obj_lib.open_browser()

            # navigate to the url
            obj_lib.page_load(browser)

            # create Home and Contact_us pages objects
            obj_home=Home(browser)
            obj_contact_us=Contact_us(browser)

            # click on Sign In button of the Home page
            browser.find_element(*obj_home.contact_us).click()

            # wait for the element to be visible in Sign in page
            obj_lib.wait_for_element(browser, obj_contact_us.subject_heading)

            # locate subject heading element and choose one of the options
            element = browser.find_element(*obj_contact_us.subject_heading)
            element.click()
            select_text = obj_lib.get_data(key='subject_heading')
            select_option = Select(element)
            select_option.select_by_visible_text(select_text)

            # fill in the email field
            valid_email_value=obj_lib.get_data(key='valid_email')
            browser.find_element(*obj_contact_us.email_address).send_keys(valid_email_value)

            # input in order reference field
            order_reference_value=obj_lib.get_data(key='references')
            browser.find_element(*obj_contact_us.order_reference).send_keys(order_reference_value)

            # fill in the message field
            message_text = obj_lib.get_data(key='contact_us_input_message')   
            browser.find_element(*obj_contact_us.message_field).send_keys(message_text) 
          
            # click Send button
            browser.find_element(*obj_contact_us.send_button).click()

            # validate that success message has appeared
            success_message=obj_lib.get_data(key='contact_us_success_message')
            assert success_message in browser.page_source
            print("Test 2 passes!")

        except Exception as e:
            # save the screenshot of the test file which has failed
            obj_lib.save_screenshot(browser)
            pytest.fail(e)
            print('Test 2 failed!')
            
        finally:
            # close the browser
            obj_lib.close_browser(browser)        
Exemple #2
0
def test_1():
    try:
        #create lib page object
        obj_lib = LIB()

        # open browser
        browser = obj_lib.open_browser()

        # navigate to the url
        obj_lib.page_load(browser)

        # create Sign_in_page object
        obj_sign_in = Sign_in(browser)

        # parse data from config.json for email and password fields
        with open('config.json') as f:
            data = json.load(f)
        email_address = data['email']
        password = data['password']

        # create Home_page object
        obj_home = Home(browser)

        # click on Sign In button of the Home page
        browser.find_element(*obj_home.sign_in).click()

        # wait for the element to be visible in Sign in page
        obj_lib.wait_for_element(browser, obj_sign_in.email_address)

        # submit the email address and password parsed from config.json to be signed with
        browser.find_element(
            *obj_sign_in.email_address).send_keys(email_address)
        browser.find_element(*obj_sign_in.password).send_keys(password)

        # click the sign in button
        browser.find_element(*obj_sign_in.sign_in_button).click()

        # check that signed in to my account has been succesfull
        try:
            sign_out_title = browser.find_element(*obj_sign_in.sign_out).title
            print(sign_out_title)
        except:
            print(
                "The web element Sign out is not fount, so you arer signed in!"
            )

        print('Test 1 passed!')

    except Exception as e:
        # save the screenshot of the test file which has failed
        obj_lib.save_screenshot(browser)
        pytest.fail(e)
        print('Test 1 failed!')

    finally:
        # close the browser
        obj_lib.close_browser(browser)
def test_4():

    try:
        # create lib page object
        obj_lib = LIB()

        # open browser
        browser = obj_lib.open_browser()

        # navigate to the url
        obj_lib.page_load(browser)

        # wait for the Women tab to be visible in Home page, locate it and click on it
        obj_home = Home(browser)
        obj_lib.wait_for_element(browser, obj_home.women)
        browser.find_element(*obj_home.women).click()

        # wait for the product names and prices in Women tab to be visible in Home page
        obj_lib.wait_for_elements(browser, obj_home.product_names)
        obj_lib.wait_for_elements(browser, obj_home.product_prices)

        # return dictionary with Women tab's products names and prices
        products_names_prices = obj_home.find_products_name_price(browser)

        # write the products names and prices in log.txt file
        obj_lib.write_to_file(products_names_prices)

    except Exception as e:
        # save the screenshot of the test file which has failed
        obj_lib.save_screenshot(browser)
        pytest.fail(e)
        print('Test 4 failed!')

    finally:
        # close the browser
        obj_lib.close_browser(browser)