def register_test_normal(self):
        '''
        c. Fill out all fields with valid values and submit the form. This will create a Customer record.
          Upon submitting the form, you’ll be taken to a new page with the option to Select an existing config.
          Disregard this page, it is not relevant to the test.
        :return: status, error_message
        '''

        self.test_username = '******'.format(self.generate_user())

        result = False
        message = ''
        try:
            # click admin in top menu
            self.driver.find_element_by_xpath('//*/a[contains(text(), "Admin")]').click()

            # open onboard section
            self.driver.find_element_by_xpath('//*/a[contains(text(), "Onboard")]').click()

            # set username and userdir
            self.driver.find_element_by_id('lastpass-disable-search-u').send_keys(self.test_username) # customer name
            self.driver.find_element_by_id('lastpass-disable-search-s').send_keys(self.test_username) # s3 folder

            # click the create customer button
            button = self.is_visible_by_x('//*/input[contains(@value, "Create")]', 20)
            button.click()

            # did we proceed to the create config page ?
            self.is_visible_by_x('//*/input[contains(@value, "Config")]', 20)

            result = True
        except Exception as e:
            message = exception_handler.generic_exception_handler_s(e, exception_handler.func_name())

        return result, message
    def verify_customer_created(self):
        '''
        c. Locate the Customer you added in step 3.
          Tip: The most recently added Customer will have the largest ID.
          You can sort the list of users in ascending or descending order by clicking the column header Id.
        :return: status, error_message/url to customer edit section on success
        '''

        status = False
        try:
            # click admin in top menu
            self.driver.find_element_by_xpath('//*/a[contains(text(), "Customers")]').click()

            # customers list
            self.driver.find_element_by_xpath('//*/ul/li/a[contains(text(), "List")]').click()

            # wait for table to load
            table = self.is_visible_by_x('//*/table', 20)

            # check if user was created
            #names = [tr.get_attribute('data-name') for tr in table.find_elements_by_tag_name('tr')]
            #status = self.test_username in names

            elems = self.driver.find_elements_by_xpath('//*/tr[@data-name="{}"]'.format(self.test_username))
            if len(elems) == 0:
                raise Exception('Username={} missing in user list'.format(self.test_username))

            # get the user edit url
            message = elems[0].find_element_by_tag_name('a').get_attribute('href')
            status = True

        except Exception as e:
            message = exception_handler.generic_exception_handler_s(e, exception_handler.func_name())

        return status, message
Exemplo n.º 3
0
    def do_search(self, search_term):

        status = False
        msg = ''
        try:

            # google homepage
            self.driver.get('https://www.google.com/')

            # wait for page to load
            search = self.is_visible_by_x('//*/input[@name="q"]', 60)

            search.send_keys(search_term)
            search.send_keys(u'\ue007')

            # wait for results page
            time.sleep(10)
            self.is_visible_by_x('//*/input[@name="q"]', 60)

            status = True

        except Exception as e:
            msg = exception_handler.generic_exception_handler_s(e, exception_handler.func_name())

        return status, msg
Exemplo n.º 4
0
    def click_urls(self, clicks_count):

        status = True
        msg = ''
        try:

            for i in range(clicks_count):
                elems = self.driver.find_elements_by_xpath('//*/a/h3')
                if len(elems) == 0:
                    raise Exception('elems==0')

                e = elems[random.randint(i, len(elems)-1)]
                try:
                    print (u"Clicking={}".format(e.text))
                except Exception:
                    pass
                self.click_js(e)

                # wait
                time.sleep(random.randint(*self.delay_general))

                # return back
                self.return_back()

                # wait
                time.sleep(random.randint(*self.delay_general))

        except Exception as e:
            status = False
            msg = exception_handler.generic_exception_handler_s(e, exception_handler.func_name())

        return status, msg
Exemplo n.º 5
0
    def posts_like(self):

        status = False
        msg = ''
        try:
            pass
        except Exception as e:
            msg = exception_handler.generic_exception_handler_s(
                e, exception_handler.func_name())

        return status, msg
Exemplo n.º 6
0
    def news_browse(self):

        status = False
        msg = ''
        try:

            # news feed is on homepage
            self.driver.get('https://www.facebook.com/')

            actions = random.randint(*self.range_actions)
            print("Number of actions on feeds page={}".format(actions))
            likes = 0
            for i in range(actions):

                # sleep before the action
                time.sleep(random.randint(*self.delay_actions))

                rnd = random.randint(0, self.prob_total)

                # do some actions like scroll
                if 0 <= rnd <= self.prob_action_scroll:
                    self.scroll_down_js(random.randint(*self.range_scroll))
                    print("Action=Scrolling page...")
                    continue

                rnd -= self.prob_action_scroll
                # add like
                if 0 <= rnd <= self.prob_action_like:
                    print("Action=Like")
                    self.do_random_like()
                    likes += 1
                    continue

                # check profile
                self.do_check_profile()
                print("Action=Check profile")

            if likes < 1:
                for i in range(random.randint(*self.range_likes)):
                    self.do_random_like()
                    likes += 1
                    time.sleep(random.randint(*self.delay_actions))

            print("Likes={}".format(likes))
            status = True

        except Exception as e:
            msg = exception_handler.generic_exception_handler_s(
                e, exception_handler.func_name())

        return status, msg
    def register_test_blank(self):
        '''
        3.b. Test the form’s validation by leaving each required field (indicated by an asterisk) blank 
            and verifying that the expected error message is displayed.
        :return: True/False -> Test succeeded/failed, error_message 
        '''

        result = False
        message = ''
        try:
            # click admin in top menu
            self.driver.find_element_by_xpath('//*/a[contains(text(), "Admin")]').click()

            # click onboard section
            self.driver.find_element_by_xpath('//*/a[contains(text(), "Onboard")]').click()

            # click the create customer button
            button = self.is_visible_by_x('//*/input[contains(@value, "Create")]', 20)
            button.click()

            # check errors
            '''
            <ul id="errors" style="display: block;">
            <li>Customer name required</li>
            <li>S3 folder required</li>
            <li>Invalid email address</li></ul>
            '''
            lis = self.driver.find_element_by_id('errors').find_elements_by_tag_name('li')
            if len(lis) != 3:
                raise Exception("expected error message is missing")

            error_messages = [li.text for li in lis]
            expected_messages = [
                'Customer name required', 'S3 folder required', 'Invalid email address'
            ]
            for e in expected_messages:
                if not e in error_messages:
                    raise Exception("expected error message is missing. missing={}".format(e))

            result = True

        except Exception as e:
            message = exception_handler.generic_exception_handler_s(e, exception_handler.func_name())

        return result, message
    def watch_videos(self):

        status = True
        msg = ''
        try:

            self.driver.get('https://youtube.com')

            # wait for page to load
            self.is_visible_by_id("search", 60)

            watches = random.randint(*self.prob_videos)
            print("Number of videos to check={}".format(watches))

            for i in range(watches):

                # open random video
                elems = self.driver.find_elements_by_xpath(
                    '//*/a[@id="thumbnail"]')
                if len(elems) == 0:
                    raise Exception("elems==0")

                e = random.sample(elems, 1)[0]
                print("Opening video href={}".format(e.get_attribute('href')))
                self.click_js(e)

                # watch for some time
                sleep_time = random.randint(*self.delay_watch)
                print("Sleeping for {} seconds".format(sleep_time))
                time.sleep(sleep_time)

                # return
                self.return_back()

                # wait for page to load
                self.is_visible_by_id("search", 60)

            status = True

        except Exception as e:
            status = False
            msg = exception_handler.generic_exception_handler_s(
                e, exception_handler.func_name())

        return status, msg
Exemplo n.º 9
0
    def video_watch(self):

        url = 'https://www.facebook.com/watch/latest/'

        status = False
        msg = ''
        try:

            # open page
            self.driver.get(url)

            watch = random.randint(*self.range_videos)
            print("Watching {} videos".format(watch))
            for i in range(watch):

                # wait for page
                self.is_visible_by_x('//*/button[contains(text(), "Watch")]',
                                     60)

                # get watch buttons
                elements = self.driver.find_elements_by_xpath(
                    '//*/button[contains(text(), "Watch")]')

                # click on random
                e = random.sample(elements, 1)[0]
                self.click_js(e)

                # watch for some time
                watch_time = random.randint(*self.delay_video_watch)
                print("Watching video for {} seconds".format(watch_time))
                time.sleep(watch_time)

                # return to previous page
                self.return_back()

            status = True
        except Exception as e:
            msg = exception_handler.generic_exception_handler_s(
                e, exception_handler.func_name())

        return status, msg
Exemplo n.º 10
0
    def friend_send_request(self):
        '''
        Send friend request to a random user. Use the top panel in the personal feed.
        :return: 
        '''

        status = False
        msg = ''
        try:

            self.driver.get('https://www.facebook.com/')

            # open profile
            self.is_visible_by_x('//*[@data-click="profile_icon"]', 60).click()

            # wait for buttons
            self.is_visible_by_x('//*[@aria-label="Add Friend"]', 60)

            # add friend buttons
            # notes: use only first 6 as the rest is not visible and would just raise a exception
            buttons = self.driver.find_elements_by_xpath(
                '//*[@aria-label="Add Friend"]')

            to_add = random.randint(*self.prob_add_friend)
            # pick random button and click
            for button in random.sample(buttons, to_add):
                #button.click()
                self.click_js(button)

                self.sleep_general()

            print('Sent {} friend requests'.format(to_add))
            status = True

        except Exception as e:
            msg = exception_handler.generic_exception_handler_s(
                e, exception_handler.func_name())

        return status, msg