예제 #1
0
    def test_one_instance_of_file_logger(self):
        class MyPage(Page):
            pass

        path_to_log = os.path.join(os.getcwd(), "po_log.txt")

        # Clear the log in case any other test has written to it. Set up deals with
        # po_log.txt at tests/scenarios directory.
        f = open(path_to_log, "w")
        f.write("")
        f.close()

        # Now log from two different page objects
        Page().log("hello", is_console=False)
        MyPage().log("world", is_console=False)
        f = open(path_to_log)
        log_content = f.read()
        try:
            # We expect to see two lines in the log, logged in order from Page to My Page.
            self.assertRegexpMatches(
                log_content,
                r".+ - INFO - Page - hello\n.+ - INFO - My Page - world$")

            # 3 lines are really 2 lines because of final line break
            self.assertEquals(len(log_content.split("\n")), 3)

        finally:
            f.close()

            os.unlink(path_to_log)
class TestWidgetItem(unittest.TestCase):

    def test_widget_item(self):
        self.widget_item_page = widget_template.WidgetItemPage()
        self.widget_item_page.open_browser("http://www.google.com", "phantomjs")
        self.widget_item_page.go_to({"category": "home-and-garden", "id": "123"})
        self.widget_item_page.title_should_be("Cool Widget")

    def test_no_uri_template(self):
        self.p = Page()
        self.p.baseurl = 'https://www.google.com/'
        self.p.open()
        self.p.title_should_be('Google')

    def tearDown(self):
        try:
            self.widget_item_page.close()
        except AttributeError:
            pass
class BaseMethodLocationShouldBeTestCase2(unittest.TestCase):
    baseurl = "file://%s" % os.path.join(os.path.dirname(os.path.realpath(__file__)), "site")

    def test_location_should_be_for_absolute_path(self):
        os.environ["PO_BASEURL"] = self.baseurl
        Page.uri = "/index.html"
        self.p = Page()
        self.p.open()
        self.p.location_should_be(os.path.join(self.baseurl, "index.html"))

    def tearDown(self):
        self.p.close()
class BaseMethodLocationShouldBeTestCase2(unittest.TestCase):
    baseurl = "file://%s" % os.path.join(
        os.path.dirname(os.path.realpath(__file__)), "site")

    def test_location_should_be_for_absolute_path(self):
        os.environ["PO_BASEURL"] = self.baseurl
        Page.uri = "/index.html"
        self.p = Page()
        self.p.open()
        self.p.location_should_be(os.path.join(self.baseurl, "index.html"))

    def tearDown(self):
        self.p.close()
예제 #5
0
 def test_log_non_string(self):
     try:
         Page().log([1, 2, 3], is_console=False)
     except TypeError:
         self.fail("Logging a non string causes a TypeError")
 def test_location_should_be_for_relative_path(self):
     os.environ["PO_BASEURL"] = self.baseurl
     Page.uri = "/index.html"
     self.p = Page()
     self.p.open()
     self.p.location_should_be("/index.html")
 def test_location_should_be_for_absolute_path(self):
     os.environ["PO_BASEURL"] = self.baseurl
     Page.uri = "/index.html"
     self.p = Page()
     self.p.open()
     self.p.location_should_be(os.path.join(self.baseurl, "index.html"))
 def test_location_should_be_for_absolute_path(self):
     os.environ["PO_BASEURL"] = self.baseurl
     Page.uri = "/index.html"
     self.p = Page()
     self.p.open()
     self.p.location_should_be(os.path.join(self.baseurl, "index.html"))
예제 #9
0
class IVTreeHomePage(Page):
    selectors = {
        "Home_menu": "xpath=(//a[contains(text(),'Home')])[1]",
        "Company_menu": "xpath=(//a[contains(text(),'Company')])[1]",
        "Your_email": "xpath=//input[contains(@name,'EMAIL')]",
        "Submit_button": "xpath=//input[contains(@value,'Send')]",
        "News_letter": "xpath=//div[contains(@class,'letter-title ')]",
        "Product_menu": "xpath=(//a[contains(text(),'Products')])[1]",
        "Click_sales": "xpath=//a[contains(text(),'*****@*****.**')]",
        #Client Area
        "client_menu": "xpath=(//a[contains(text(),'Client Area')])[1]",
        "userName_Login": "******",
        "password_Login": "******",
        "Sigin_button": "xpath=//input[contains(@name,'login_submit')]",
        "SiginUp_Client": "xpath=//a[contains(text(),'Sign Up')]",
    }

    def __init__(self, *args, **kwargs):
        Page.__init__(self)
        self.Utility_obj = Utility()

    def scroll__bar(self):
        '''
        scrolling of scroll-bar in a page
        :param text:
        :return:
        '''
        alert = None
        try:
            alert = self._current_browser().switch_to_alert()
            logger.info("scrolled ")
            return alert
            self.execute_javascript("current_prompt.scrollBy(0,450)")
            time.sleep(8)

        except:
            raise RuntimeError('There were no alerts')

    def Navigate_Between_HomeCompany(self, email):
        '''
        this functions helps to navigate between home and company module
        and passing emailID to get NewsLetter of product
        :param email:
        :return:
        '''
        self.click_element("Home_menu")
        self.driver.execute_script(
            "window.scrollTo(0, document.body.scrollHeight);")
        time.sleep(10)
        self.click_element("Company_menu")
        second = range(0, 5)
        for sec in second:
            if sec >= 5:
                break
            self.driver.execute_script("window.scrollBy(0,1500)", "")
            time.sleep(5)
        self.get_text("News_letter")
        self.input_text("Your_email", email)
        self.click_button("Submit_button")
        # taking screenshot at last of operation
        self.Utility_obj.takescreen()
        logger.info("Navigation succesful", html=True)
        return self

    def Products_Module(self):
        '''
        THIS FUNCTIONS HELPS US TO GET SALES DETAILS OF PRODUCT
        :return:
        '''
        self.click_element("Product_menu")
        self.driver.execute_script(
            "window.scrollTo(0, document.body.scrollHeight);")
        time.sleep(10)
        self.click_element("Click_sales")
        # taking screenshot at last of operation
        #self.Utility_obj.takescreen()
        logger.info('Product modules succesfully clicked sales', html=True)
        return self

    def Client_AreaModule(self, login, username, password):
        '''

        :return:
        '''
        self.click_element("client_menu")
        heading = self.get_title()
        self.title_should_be(title=heading)
        if login == 'Have Account':
            self.input_text("userName_Login", username)
            self.input_password("password_Login", password)
            self.click_element("Sigin_button")
        else:
            self.click_element("SiginUp_Client")

        # taking screenshot at last of operation
        self.Utility_obj.takescreen()
        logger.info("Client area developed", html=True)
        return self

    def Products_Module1_test(self):
        '''
        THIS FUNCTIONS HELPS US TO GET SALES DETAILS OF PRODUCT
        :return:
        '''
        self.click_element("Product_menu")
        time.sleep(10)
        self.Utility_obj.takescreen()
        logger.info('Product modules 1 succesfully clicked sales', html=True)
        return self

    def Products_Module2_test(self):
        '''
        THIS FUNCTIONS HELPS US TO GET SALES DETAILS OF PRODUCT
        :return:
        '''
        print "Product Testing "
        # taking screenshot at last of operation
        logger.info('Product modules 2 succesfully clicked sales', html=True)
        return self

    def Products_Module3_test(self):
        '''
        THIS FUNCTIONS HELPS US TO GET SALES DETAILS OF PRODUCT
        :return:
        '''
        print "Product Testing "
        # taking screenshot at last of operation
        logger.info('Product modules 3 succesfully clicked sales', html=True)
        return self

    def Products_Module4_test(self):
        '''
        THIS FUNCTIONS HELPS US TO GET SALES DETAILS OF PRODUCT
        :return:
        '''
        print "Product Testing "
        # taking screenshot at last of operation
        logger.info('Product modules 4 succesfully clicked sales', html=True)
        return self

    def Products_Module5_test(self):
        '''
        THIS FUNCTIONS HELPS US TO GET SALES DETAILS OF PRODUCT
        :return:
        '''
        print "Product Testing "
        # taking screenshot at last of operation
        print "Product Testing "
        # taking screenshot at last of operation
        logger.info('Product modules 5 succesfully clicked sales', html=True)
        return self

    def Products_Module6_test(self):
        '''
        THIS FUNCTIONS HELPS US TO GET SALES DETAILS OF PRODUCT
        :return:
        '''
        print "Product Testing "
        # taking screenshot at last of operation
        logger.info('Product modules 6 succesfully clicked sales', html=True)
        return self

    def Products_Module7_test(self):
        '''
        THIS FUNCTIONS HELPS US TO GET SALES DETAILS OF PRODUCT
        :return:
        '''
        print "Product Testing "
        # taking screenshot at last of operation
        logger.info('Product modules 7 succesfully clicked sales', html=True)
        return self

    def Product_Feature1_Test(self):
        '''
        THIS FUNCTIONS HELPS US TO GET SALES DETAILS OF PRODUCT
        :return:
        '''
        print "Product Feature "
        # taking screenshot at last of operation
        logger.info('Product modules 2 succesfully clicked sales', html=True)
        return self

    def Product_Feature2_Test(self):
        '''
        THIS FUNCTIONS HELPS US TO GET SALES DETAILS OF PRODUCT
        :return:
        '''
        print "Product Feature "
        # taking screenshot at last of operation
        logger.info('Product modules 2 succesfully clicked sales', html=True)
        return self

    def Product_Feature3_Test(self):
        '''
        THIS FUNCTIONS HELPS US TO GET SALES DETAILS OF PRODUCT
        :return:
        '''
        print "Product Feature "
        # taking screenshot at last of operation
        logger.info('Product modules 2 succesfully clicked sales', html=True)
        return self

    def Product_Feature4_Test(self):
        '''
        THIS FUNCTIONS HELPS US TO GET SALES DETAILS OF PRODUCT
        :return:
        '''
        print "Product Feature "
        # taking screenshot at last of operation
        logger.info('Product modules 2 succesfully clicked sales', html=True)
        return self

    if __name__ == "__main__":
        Page.main()
예제 #10
0
 def __init__(self, *args, **kwargs):
     Page.__init__(self)
     self.Utility_obj = Utility()
 def test_no_uri_template(self):
     self.p = Page()
     self.p.baseurl = 'https://www.google.com/'
     self.p.open()
     self.p.title_should_be('Google')
 def test_location_should_be_for_relative_path(self):
     os.environ["PO_BASEURL"] = self.baseurl
     Page.uri = "/index.html"
     self.p = Page()
     self.p.open()
     self.p.location_should_be("/index.html")
예제 #13
0
 def __init__(self):
     Page.__init__(self)
     
     if not self.selectors:
         obj_selectors = self.get_selectors_from_obj_file()
         self.selectors.update(obj_selectors)