Ejemplo n.º 1
0
class SimpleAndroidTests(unittest.TestCase):
    def setUp(self):
        self.udid = sys.argv[1]
        self.capture_cap = sys.argv[3]
        self.device_id = self.udid

        desired_caps = {}
        desired_caps['platformName'] = 'iOS'
        desired_caps['automationName'] = 'XCUITest'
        desired_caps['udid'] = self.device_id
        desired_caps['deviceName'] = self.device_id
        desired_caps['bundleId'] = "com.globo.hydra"
        desired_caps['newCommandTimeout'] = 600
        if self.capture_cap == "1":
            desired_caps['headspin.capture'] = True
        else:
            desired_caps['headspin.capture'] = False
        desired_caps['no-reset'] = True

        self.os = "iOS"
        self.status = "Fail_Launch"
        self.home_pg_load_time = 0
        self.app_launch_time = 0
        self.series_load_time = 0
        self.video_laod_time = 0
        self.buffer_in_video = False
        self.session_id = None
        self.kpi_dic = {}
        self.test_name = "Globo_Play_Video"
        self.pass_count = 0
        self.fail_count = 0

        self.alerts = SendAlert()

        # Start the log cature
        self.timestamp = str(int(round(time.time() * 1000)))
        self.path = os.getcwd() + "/logs/" + str(self.timestamp)
        print self.path
        os.mkdir(self.path)

        self.process = subprocess.Popen(
            "exec " + "idevicesyslog -u " + self.device_id + " > " +
            self.path + "/" + str(self.timestamp) + '_' + self.device_id +
            ".log",
            shell=True)

        appium_input = sys.argv[2]
        if appium_input.isdigit():
            self.url = ('http://127.0.0.1:' + appium_input + '/wd/hub')
        else:
            self.url = appium_input
        print self.url

        self.driver = webdriver.Remote(self.url, desired_caps)

        self.start_app = int(round(time.time() * 1000))

    def tearDown(self):

        print "Pass count is %s" % self.pass_count
        if self.pass_count != 5:
            self.fail_count = 5 - self.pass_count
        else:
            self.fail_count = 0
        print "Fail count is %s " % self.fail_count
        if self.capture_cap == "1":
            self.session_id = self.driver.session_id
            print self.session_id
        else:
            self.session_id = None

        screenshot_name = str(self.timestamp) + "_" + self.device_id + ".png"
        self.driver.save_screenshot(self.path + "/" + screenshot_name)

        if self.status != "Pass":
            print self.driver.page_source.encode('utf-8')
        screenshot_path = self.path + "/" + screenshot_name

        log_file_name = str(self.timestamp) + "_" + self.device_id + ".log"
        log_path = self.path + "/" + log_file_name

        s3 = boto3.resource('s3')
        s3.meta.client.upload_file(screenshot_path,
                                   'grafana-images.headspin.io',
                                   'globo/' + screenshot_name)
        s3.meta.client.upload_file(log_path, 'grafana-images.headspin.io',
                                   'globo/' + log_file_name)
        print "Pushed to AWS"

        log_url = "https://s3-us-west-2.amazonaws.com/grafana-images.headspin.io/globo/" + log_file_name
        png_url = "https://s3-us-west-2.amazonaws.com/grafana-images.headspin.io/globo/" + screenshot_name

        self.threshold = 5000
        if not all(
                i < self.threshold
                for i in list(self.kpi_dic.values())) or self.status != "Pass":
            slack_messge = []
            message_to_be_send = ""
            if not all(i < self.threshold
                       for i in list(self.kpi_dic.values())):

                for key, value in self.kpi_dic.items():
                    if value > self.threshold:
                        slack_messge.append('{} : {}'.format(key, value))
                for text in slack_messge:
                    message_to_be_send = message_to_be_send + text + "\n"
                print message_to_be_send
            message_to_be_send = self.os+"\n"+self.udid+"\n"+message_to_be_send + \
                "\n" + "Device_log url:"+log_url+"\n"+"Device screenshot url:"+png_url
            # slack alert
            self.alerts.slack_alert(message_to_be_send)

            # Mail ALert
            self.alerts.email_alert(message_to_be_send)

    # Insert to app table
        insert = MysqlDataInsert()
        insert.globo_kpi_metrics(self.driver, self.app_launch_time,
                                 self.home_pg_load_time, self.series_load_time,
                                 self.video_laod_time, self.buffer_in_video,
                                 self.pass_count, self.fail_count, self.status,
                                 self.timestamp, self.session_id,
                                 self.test_name)

        print self.process.pid
        self.process.kill()

        # end the session
        self.driver.quit()

    def test_globo(self):
        # App Launch
        self.driver.implicitly_wait(50)

        # Check if the app lauunch is completed
        home_button = self.driver.find_element_by_name("Agora")

        launched_app = int(round(time.time() * 1000))

        # calcualting launch time
        self.app_launch_time = launched_app - self.start_app
        print("App Launch Time is %s ms" % self.app_launch_time)
        d = {'globo_launch_time': self.app_launch_time}
        self.kpi_dic.update(d)

        self.pass_count = self.pass_count + 1

        sleep(5)

        # login
        self.status = "Fail_login"
        screen_size = self.driver.get_window_size()
        width = screen_size['width']
        height = screen_size['height']
        tap_x = width * 0.956
        tap_y = height * 0.042

        # profile_button tap
        self.driver.tap([(tap_x, tap_y)])

        # logout

        try:
            self.driver.implicitly_wait(5)
            logout_button = self.driver.find_element_by_name("Sair")
            logout_button.click()
            confirm_button = self.driver.find_element_by_name("Sim")
            confirm_button.click()
            self.driver.find_element_by_class_name(
                "XCUIElementTypeNavigationBar")

        except:
            pass

        self.driver.implicitly_wait(30)
        sleep(3)
        # tap on profile button
        self.driver.tap([(tap_x, tap_y)])
        entrar = self.driver.find_element_by_name("Entrar")
        entrar.click()

        email_id = self.driver.find_element_by_name("e-mail")
        email_id.click()
        email_id.set_value('laurent_headspin')

        password = self.driver.find_element_by_name("senha")
        password.click()
        password.set_value('Globo@321')

        login_button = self.driver.find_element_by_name("ENTRAR")
        login_button.click()

        self.status = "Fail_page_load_post_login"

        self.driver.find_element_by_name("Sair")

        close_x_tap = width * 0.813
        close_y_tap = height * 0.220

        self.driver.tap([(close_x_tap, close_y_tap)])

        start_login = int(round(time.time() * 1000))
        home_button = self.driver.find_element_by_name("Agora")
        self.driver.find_element_by_class_name("XCUIElementTypeImage")
        end_login = int(round(time.time() * 1000))

        self.home_pg_load_time = end_login - start_login
        print("Home page loading time is %s ms" % self.home_pg_load_time)

        d = {'globo_post_login_home_load_time': self.home_pg_load_time}
        self.kpi_dic.update(d)

        self.pass_count = self.pass_count + 1

        sleep(2)

        # series view time

        categories_tab = self.driver.find_element_by_name("Categorias")
        categories_tab.click()
        sleep(3)

        series_tab = self.driver.find_element_by_name("Séries")
        location = series_tab.location
        size = series_tab.size
        self.x_tap = location['x'] + int(size['width'] / 2)
        self.y_tap = location['y'] + int(size['height'] / 2)
        sleep(3)
        self.driver.tap([(self.x_tap, self.y_tap)])

        sleep(8)

        first_poster_tab = self.driver.find_element_by_class_name(
            "XCUIElementTypeImage")
        first_poster_tab.click()

        self.driver.tap([(64, 161)])
        #	location = first_poster_tab.location
        #	size = first_poster_tab.size
        #	self.x_tap = location['x']+int(size['width']/2)
        #	self.y_tap= location['y']+int(size['height']/2)
        #	print self.x_tap,self.y_tap
        #
        #	self.driver.tap([(self.x_tap,self.y_tap)])

        series_load_start = int(round(time.time() * 1000))
        self.driver.find_element_by_name("Episódios")
        series_load_end = int(round(time.time() * 1000))

        self.series_load_time = series_load_end - series_load_start
        d = {'globo_series_page_load_time': self.series_load_time}
        self.kpi_dic.update(d)
        print "Series load time", self.series_load_time
        self.pass_count = self.pass_count + 1

        sleep(2)

        # video playback
        self.status = "Fail_video_play"
        self.driver.implicitly_wait(10)
        continue_button = self.driver.find_element_by_name(
            "titleHighlightViewCellFirstButton")
        sleep(4)
        continue_button = self.driver.find_element_by_name(
            "titleHighlightViewCellFirstButton")
        location = continue_button.location
        size = continue_button.size
        self.x_tap = location['x'] + int(size['width'] / 2)
        self.y_tap = location['y'] + int(size['height'] / 2)
        print self.x_tap, self.y_tap
        try:
            continue_button.click()
        except:
            self.driver.tap([(self.x_tap, self.y_tap)])

        video_start = int(round(time.time() * 1000))
        t_end_ad = time.time() + 60
        cmd = shlex.split("idevicesyslog -u  %s" % self.device_id)
        process = subprocess.Popen(cmd, stdout=subprocess.PIPE)

        for line in iter(process.stdout.readline, b''):
            if "FigStreamPlayer" in line:
                print "VideoPlayed"
                video_end = int(round(time.time() * 1000))
                break
            if time.time() > t_end_ad:
                break
        process.kill()
        self.video_laod_time = video_end - video_start

        self.driver.implicitly_wait(5)
        try:
            oops_button = self.driver.find_element_by_name("OK")
            oops_button.click()
            sleep(2)
            self.driver.tap([(self.x_tap, self.y_tap)])

            video_second = int(round(time.time() * 1000))
            t_end_ad = time.time() + 60
            cmd = shlex.split("idevicesyslog -u  %s" % self.device_id)
            process = subprocess.Popen(cmd, stdout=subprocess.PIPE)

            for line in iter(process.stdout.readline, b''):
                if "FigStreamPlayer" in line:
                    print "VideoPlayed"
                    video_play = int(round(time.time() * 1000))
                    break
                if time.time() > t_end_ad:
                    break
            process.kill()
            self.video_laod_time = video_play - video_second
        except:
            pass
        print "Video load time ", self.video_laod_time

        d = {'globo_video_load_time': self.video_laod_time}
        self.kpi_dic.update(d)
        sleep(5)
        self.pass_count = self.pass_count + 1

        self.buffer_in_video = False
        self.driver.implicitly_wait(1)
        t_end = time.time() + 60
        while time.time() < t_end:
            try:
                spinner = self.driver.find_element_by_name("spinner")
                self.buffer_in_video = True
                break
            except:
                pass

        if self.buffer_in_video:
            self.status = "Video_interrupted"
        else:
            self.status = "Pass"
            self.pass_count += 1
Ejemplo n.º 2
0
class Globo_Continue_Assista_iOS(unittest.TestCase):
    # check if the necessary folders are present, if not create
    def check_dir(self, dir_path):
        while True:
            try:
                os.mkdir(dir_path)
            except:
                break

    def adb_dump_data(self, udid, reference, step, adb_dump_dir):
        # save the sys dump of the phone
        self.adb_activities.get_dumpsys(udid, reference, step, adb_dump_dir)
        # Get the cpu info
        cpu_usage = self.adb_activities.get_cpuinfo(udid)
        # Get mem info
        mem_usage = self.adb_activities.get_mem_info(udid, self.package)
        # Device temp
        temperature = self.adb_activities.get_device_temp(udid)
        print step, cpu_usage, mem_usage, temperature
        return [step, cpu_usage, mem_usage, temperature]

    def setUp(self):
        self.reference = str(int(time.time() * 1000))
        self.package = "com.globo.hydra"
        # device id as 1st argument
        self.device_id = sys.argv[1]
        self.os = "iOS"

        self.adb_activities = AdbDdata()
        self.alerts = SendAlert()
        self.array_of_data_list = []
        # Before test function
        # self.adb_activities.before_test(self.device_id)
        self.capture_cap = sys.argv[3]
        # desired caps for the app
        desired_caps = {}
        desired_caps['platformName'] = self.os
        desired_caps['automationName'] = 'XCUITest'
        desired_caps['udid'] = self.device_id
        desired_caps['deviceName'] = self.device_id
        desired_caps['bundleId'] = self.package
        desired_caps['newCommandTimeout'] = 600
        desired_caps['no-reset'] = True

        if self.capture_cap == "1":
            desired_caps['headspin:capture'] = True
        else:
            desired_caps['headspin:capture'] = False
        self.status = "Fail_Launch"
        self.path = os.getcwd() + "/logs/" + str(self.reference)
        print self.path
        self.check_dir(self.path)
        self.process = subprocess.Popen(
            "exec " + "idevicesyslog -u " + self.device_id + " > " +
            self.path + "/" + str(self.reference) + '_' + self.device_id +
            ".log",
            shell=True)
        appium_input = sys.argv[2]
        if appium_input.isdigit():
            self.url = ('http://127.0.0.1:' + appium_input + '/wd/hub')
        else:
            self.url = appium_input

        # launching app
        self.driver = webdriver.Remote(self.url, desired_caps)
        self.start_app = int(round(time.time() * 1000))

        # initialising variables
        self.status = "Fail_launch"
        self.app_launch_time = 0

        self.status_dic = {}
        self.kpi_dic = {}

        self.app_launch_time = 0
        self.home_pg_load_time = 0
        self.initial_video_play = 0
        self.sub_video_play = 0
        self.title_check = False
        self.progress_check = False
        self.test_name = "Continue_Assistindo"
        self.kpi_count = 6
        self.pass_count = 0
        self.fail_count = 0

    def tearDown(self):
        # incrementing kpi count
        print "Pass count is %s" % self.pass_count
        if self.pass_count != self.kpi_count:
            self.fail_count = self.kpi_count - self.pass_count
        else:
            self.fail_count = 0
        print "Fail count is %s " % self.fail_count

        if self.capture_cap == "1":
            self.session_id = self.driver.session_id
            print self.session_id
        else:
            self.session_id = None
        # Insert to app table
        insert = MysqlDataInsert()
        insert.globo_continuar_metrics(
            self.driver, self.app_launch_time, self.home_pg_load_time,
            self.initial_video_play, self.title_check, self.progress_check,
            self.sub_video_play, self.pass_count, self.fail_count, self.status,
            self.reference, self.session_id, self.test_name)

        screenshot_name = str(self.reference) + "_" + self.device_id + ".png"
        self.driver.save_screenshot(self.path + "/" + screenshot_name)

        screenshot_path = self.path + "/" + screenshot_name

        log_file_name = str(self.reference) + "_" + self.device_id + ".log"
        log_path = self.path + "/" + log_file_name

        s3 = boto3.resource('s3')
        s3.meta.client.upload_file(screenshot_path,
                                   'grafana-images.headspin.io',
                                   'globo/' + screenshot_name)
        s3.meta.client.upload_file(log_path, 'grafana-images.headspin.io',
                                   'globo/' + log_file_name)
        print "Pushed to AWS"

        log_url = "https://s3-us-west-2.amazonaws.com/grafana-images.headspin.io/globo/" + log_file_name
        png_url = "https://s3-us-west-2.amazonaws.com/grafana-images.headspin.io/globo/" + screenshot_name

        self.threshold = 5000
        if not all(
                i < self.threshold
                for i in list(self.kpi_dic.values())) or self.status != "Pass":
            slack_messge = []
            message_to_be_send = ""
            if not all(i < self.threshold
                       for i in list(self.kpi_dic.values())):
                for key, value in self.kpi_dic.items():
                    if value > self.threshold:
                        slack_messge.append('{} : {}'.format(key, value))
                for text in slack_messge:
                    message_to_be_send = message_to_be_send + text + "\n"
                print message_to_be_send
            message_to_be_send = self.os+"\n"+self.device_id+"\n"+message_to_be_send + \
                "\n" + "Device_log url:"+log_url+"\n"+"Device screenshot url:"+png_url
            # slack alert
            self.alerts.slack_alert(message_to_be_send)
            # Mail ALert
            self.alerts.email_alert(message_to_be_send)
        self.driver.quit()

    def videoplay_check(self, sec):
        self.driver.implicitly_wait(5)
        t_end = time.time() + sec
        while time.time() < t_end:
            try:
                self.driver.find_element_by_accessibility_id(
                    'Container').click()
                player_control = self.driver.find_element_by_accessibility_id(
                    "PlayPauseButton")
                sleep(5)
            except:
                try:
                    spinner = self.driver.find_element_by_accessibility_id(
                        'Conexão da rede em andamento')
                except:
                    continue
                print "Video Interrupted"
                self.video_play()

    def video_play(self):
        self.driver.implicitly_wait(30)
        t_end = time.time() + 10
        cmd = shlex.split("idevicesyslog -u  %s" % self.device_id)
        process = subprocess.Popen(cmd, stdout=subprocess.PIPE)

        for line in iter(process.stdout.readline, b''):
            if "FigStreamPlayer" in line:
                print "VideoPlayed"
                video_end = int(round(time.time() * 1000))
                break
            if time.time() > t_end:
                break
        process.kill()

    def test_login(self):
        # App Launch
        self.driver.implicitly_wait(50)
        # Check if the app lauunch is completed
        home_button = self.driver.find_element_by_name("Agora")
        launched_app = int(round(time.time() * 1000))
        # calculating launch time
        self.app_launch_time = launched_app - self.start_app
        print("App Launch Time is %s ms" % self.app_launch_time)
        d = {'globo_launch_time': self.app_launch_time}
        self.kpi_dic.update(d)
        self.pass_count = self.pass_count + 1
        sleep(5)
        # login
        self.status = "Fail_login"
        screen_size = self.driver.get_window_size()
        width = screen_size['width']
        height = screen_size['height']
        tap_x = width * 0.956
        tap_y = height * 0.042
        # profile_button tap
        self.driver.tap([(tap_x, tap_y)])
        # logout
        try:
            self.driver.implicitly_wait(5)
            logout_button = self.driver.find_element_by_name("Sair")
            logout_button.click()
            confirm_button = self.driver.find_element_by_name("Sim")
            confirm_button.click()
            self.driver.find_element_by_class_name(
                "XCUIElementTypeNavigationBar")
        except:
            pass
        self.driver.implicitly_wait(30)
        sleep(3)
        # tap on profile button
        self.driver.tap([(tap_x, tap_y)])
        entrar = self.driver.find_element_by_name("Entrar")
        entrar.click()
        email_id = self.driver.find_element_by_name("e-mail")
        email_id.click()
        email_id.set_value('laurent_headspin')
        password = self.driver.find_element_by_name("senha")
        password.click()
        password.set_value('Globo@321')
        login_button = self.driver.find_element_by_name("ENTRAR")
        login_button.click()
        self.status = "Fail_page_load_post_login"

        self.driver.find_element_by_name("Sair")
        close_x_tap = width * 0.813
        close_y_tap = height * 0.220
        self.driver.tap([(close_x_tap, close_y_tap)])

        start_login = int(round(time.time() * 1000))
        home_button = self.driver.find_element_by_name("Agora")
        self.driver.find_element_by_class_name("XCUIElementTypeImage")
        end_login = int(round(time.time() * 1000))
        self.home_pg_load_time = end_login - start_login
        print("Home page loading time is %s ms" % self.home_pg_load_time)
        d = {'globo_post_login_home_load_time': self.home_pg_load_time}
        self.kpi_dic.update(d)
        self.pass_count = self.pass_count + 1
        sleep(2)

        # Starting Continue_Assista
        categories_tab = self.driver.find_element_by_name("Categorias")
        categories_tab.click()
        sleep(3)
        series_tab = self.driver.find_element_by_name("Séries")
        try:
            series_tab.click()
        except:
            location = series_tab.location
            size = series_tab.size
            self.x_tap = location['x'] + int(size['width'] / 2)
            self.y_tap = location['y'] + int(size['height'] / 2)
            self.driver.tap([(self.x_tap, self.y_tap)])
        screen_size = self.driver.get_window_size()
        width = screen_size['width']
        height = screen_size['height']
        swipe_start_x = width / 2
        swipe_start_y = height * 0.7
        swipe_end_x = width / 2
        swipe_end_y = height * 0.3
        self.driver.implicitly_wait(5)
        #self.driver.swipe(swipe_start_x, swipe_start_y, swipe_end_x, swipe_end_y,1000)
        while True:
            try:
                title_button = self.driver.find_elements_by_class_name(
                    "XCUIElementTypeCell")[0].find_elements_by_class_name(
                        "XCUIElementTypeStaticText")[0]
                break
            except:
                self.driver.swipe(swipe_start_x, swipe_start_y, swipe_end_x,
                                  swipe_end_y, 1000)
                continue
        self.driver.implicitly_wait(10)
        title_button.click()
        try:
            title_name = self.driver.find_element_by_accessibility_id(
                "titleHighlightViewCellTitleName")
        except:
            location = title_button.location
            size = series_tab.size
            self.x_tap = location['x'] + int(size['width'] / 2)
            self.y_tap = location['y'] + int(size['height'] / 2)
            self.driver.tap([(self.x_tap, self.y_tap)], 1000)
            sleep(3)
            title_name = self.driver.find_element_by_accessibility_id(
                "titleHighlightViewCellTitleName")
        get_title_name = title_name.text.encode('utf-8')
        print get_title_name
        sleep(3)
        Details_tab = self.driver.find_element_by_accessibility_id(
            "tabViewCell1")
        if (Details_tab.text != "Detalhes"):
            Details_tab = self.driver.find_element_by_accessibility_id(
                "tabViewCell2")
        try:
            Details_tab.click()
        except:
            location = Details_tab.location
            size = Details_tab.size
            self.x_tap = location['x'] + int(size['width'] / 2)
            self.y_tap = location['y'] + int(size['height'] / 2)
            self.driver.tap([(self.x_tap, self.y_tap)])

        spec1 = self.driver.find_elements_by_class_name("XCUIElementTypeCell")[
            1].find_elements_by_class_name("XCUIElementTypeStaticText")[3].text

        sleep(2)
        play_button = self.driver.find_element_by_accessibility_id(
            "titleHighlightViewCellFirstButton")
        play_button.click()
        self.status = "Fail_video_Play"
        video_start = int(round(time.time() * 1000))

        t_end_ad = time.time() + 60
        cmd = shlex.split("idevicesyslog -u  %s" % self.device_id)
        process = subprocess.Popen(cmd, stdout=subprocess.PIPE)

        for line in iter(process.stdout.readline, b''):
            if "FigStreamPlayer" in line:
                print "VideoPlayed"
                video_end = int(round(time.time() * 1000))
                break
            if time.time() > t_end_ad:
                break
        process.kill()
        self.initial_video_play = video_end - video_start

        self.driver.implicitly_wait(5)
        try:
            oops_button = self.driver.find_element_by_name("OK")
            oops_button.click()
            sleep(2)
            return
        except:
            pass
        print "Initial Video load time ", self.initial_video_play

        self.pass_count += 1
        d = {'globo_initial_play': self.initial_video_play}
        self.kpi_dic.update(d)

        # Watch the Video for 1 minute
        self.videoplay_check(80)
        self.driver.implicitly_wait(50)
        navigate_up = self.driver.find_element_by_accessibility_id("Voltar")
        navigate_up.click()
        self.status = "Fail_get_progress"
        sleep(5)
        get_title_progress = self.driver.find_element_by_name("Progresso").text
        print get_title_progress
        sleep(2)
        #        navigate_up = self.driver.find_element_by_accessibility_id("Voltar")
        #        navigate_up.click()
        sleep(5)
        # closing and relaunching app
        self.driver.close_app()
        sleep(10)
        self.driver.launch_app()

        # App relaunched
        home_tab = self.driver.find_element_by_name("Início")
        # Searching for the same title
        search_button = self.driver.find_element_by_name("Busca")
        search_button.click()

        search_bar = self.driver.find_element_by_accessibility_id(
            "O que você quer assistir?")
        search_bar.click()
        search_bar.send_keys(get_title_name.decode('utf-8'))
        # self.driver.press_keycode(66)
        self.driver.implicitly_wait(3)
        i = 0
        while i < len(
                self.driver.find_element_by_name("searchViewCollectionView").
                find_element_by_name("titleCollectionViewCollectionView").
                find_elements_by_class_name("XCUIElementTypeCell")):
            title_select = self.driver.find_element_by_name(
                "searchViewCollectionView").find_element_by_name(
                    "titleCollectionViewCollectionView"
                ).find_elements_by_class_name("XCUIElementTypeCell")[i]
            title_select.click()
            self.status = "Fail_title_check"
            self.title_check = False
            try:
                search_title = self.driver.find_element_by_accessibility_id(
                    "titleHighlightViewCellTitleName")
            except:
                navigate_up = self.driver.find_element_by_accessibility_id(
                    "Voltar")
                navigate_up.click()
                continue
            search_title_name = search_title.text.encode('utf-8')
            print search_title_name
            sleep(3)
            Details_tab = self.driver.find_element_by_accessibility_id(
                "tabViewCell1")
            if (Details_tab.text != "Detalhes"):
                Details_tab = self.driver.find_element_by_accessibility_id(
                    "tabViewCell2")
            try:
                Details_tab.click()
            except:
                location = Details_tab.location
                size = Details_tab.size
                self.x_tap = location['x'] + int(size['width'] / 2)
                self.y_tap = location['y'] + int(size['height'] / 2)
                self.driver.tap([(self.x_tap, self.y_tap)])
            spec2 = self.driver.find_elements_by_class_name(
                "XCUIElementTypeCell")[1].find_elements_by_class_name(
                    "XCUIElementTypeStaticText")[3].text
            if (search_title_name == get_title_name) and (spec1 == spec2):
                print "Title found"
                self.title_check = True
                self.pass_count = self.pass_count + 1
                break
            else:
                i += 1
                navigate_up = self.driver.find_element_by_accessibility_id(
                    "Voltar")
                navigate_up.click()
                sleep(20)
        sleep(2)
        self.status = "Fail_progress_check"
        self.progress_check = False
        search_title_progress = self.driver.find_element_by_name(
            "Progresso").text
        print search_title_progress
        if search_title_progress == get_title_progress:
            print "Progress time verified"
            self.progress_check = True
            self.pass_count = self.pass_count + 1

        continue_button = self.driver.find_element_by_accessibility_id(
            "titleHighlightViewCellFirstButton")
        continue_button.click()

        video_start = int(round(time.time() * 1000))
        t_end_ad = time.time() + 60
        cmd = shlex.split("idevicesyslog -u  %s" % self.device_id)
        process = subprocess.Popen(cmd, stdout=subprocess.PIPE)

        for line in iter(process.stdout.readline, b''):
            if "FigStreamPlayer" in line:
                print "VideoPlayed"
                video_end = int(round(time.time() * 1000))
                break
            if time.time() > t_end_ad:
                break
        process.kill()
        self.sub_video_play = video_end - video_start
        print "subsequent video load time ", self.sub_video_play
        self.pass_count += 1
        sleep(10)
        if self.progress_check == False:
            self.status = "Fail_progress_check"
        elif self.title_check == False:
            self.status = "Fail_title_check"
        else:
            self.status = "Pass"
Ejemplo n.º 3
0
class Globo_Download_Content_iOS(unittest.TestCase):
    def setUp(self):

        self.reference = str(int(round(time.time() * 1000)))
        self.package = "com.globo.hydra"
        #device id as 1st argument
        self.device_id = sys.argv[1]
        self.os = "iOS"

        self.adb_activities = AdbDdata()
        self.alerts = SendAlert()

        #Before test function
        #self.adb_activities.before_test(self.device_id)
        self.capture_cap = sys.argv[3]

        #desired caps for the app
        desired_caps = {}
        desired_caps['platformName'] = self.os
        desired_caps['automationName'] = 'XCUITest'
        desired_caps['udid'] = self.device_id
        desired_caps['deviceName'] = self.device_id
        desired_caps['bundleId'] = self.package
        desired_caps['newCommandTimeout'] = 600
        desired_caps['no-reset'] = True
        if self.capture_cap == "1":
            desired_caps['headspin:capture'] = True
        else:
            desired_caps['headspin:capture'] = False

        self.status = "Fail_Launch"
        self.path = os.getcwd() + "/logs/" + str(self.reference)
        print self.path
        os.mkdir(self.path)
        self.process = subprocess.Popen(
            "exec " + "idevicesyslog -u " + self.device_id + " > " +
            self.path + "/" + str(self.reference) + '_' + self.device_id +
            ".log",
            shell=True)
        appium_input = sys.argv[2]
        if appium_input.isdigit():
            self.url = ('http://127.0.0.1:' + appium_input + '/wd/hub')
        else:
            self.url = appium_input
        #launching app
        self.driver = webdriver.Remote(self.url, desired_caps)
        self.start_app = int(round(time.time() * 1000))
        #initialising variables
        self.status = "Fail_launch"
        self.app_launch_time = 0
        self.status_dic = {}
        self.kpi_dic = {}

        self.app_launch_time = 0
        self.home_pg_load_time = 0
        self.video_load_time = 0
        self.download_time = 0
        self.title_check = False
        self.test_name = "Globo_Download_Content"
        self.kpi_count = 5
        self.pass_count = 0
        self.fail_count = 0

    def tearDown(self):
        #incrementing kpi count
        print "Pass count is %s" % self.pass_count
        if self.pass_count != self.kpi_count:
            self.fail_count = self.kpi_count - self.pass_count
        else:
            self.fail_count = 0
        print "Fail count is %s " % self.fail_count

        if self.capture_cap == "1":
            self.session_id = self.driver.session_id
            print self.session_id
        else:
            self.session_id = None

#Insert to app table
        insert = MysqlDataInsert()
        insert.globo_download_content(
            self.driver, self.app_launch_time, self.home_pg_load_time,
            self.video_load_time, self.title_check, self.download_time,
            self.pass_count, self.fail_count, self.status, self.reference,
            self.session_id, self.test_name)

        screenshot_name = str(self.reference) + "_" + self.device_id + ".png"
        self.driver.save_screenshot(self.path + "/" + screenshot_name)

        screenshot_path = self.path + "/" + screenshot_name

        log_file_name = str(self.reference) + "_" + self.device_id + ".log"
        log_path = self.path + "/" + log_file_name

        s3 = boto3.resource('s3')
        s3.meta.client.upload_file(screenshot_path,
                                   'grafana-images.headspin.io',
                                   'globo/' + screenshot_name)
        s3.meta.client.upload_file(log_path, 'grafana-images.headspin.io',
                                   'globo/' + log_file_name)
        print "Pushed to AWS"

        log_url = "https://s3-us-west-2.amazonaws.com/grafana-images.headspin.io/globo/" + log_file_name
        png_url = "https://s3-us-west-2.amazonaws.com/grafana-images.headspin.io/globo/" + screenshot_name

        self.threshold = 5000
        if not all(
                i < self.threshold
                for i in list(self.kpi_dic.values())) or self.status != "Pass":
            slack_messge = []
            message_to_be_send = ""
            if not all(i < self.threshold
                       for i in list(self.kpi_dic.values())):
                for key, value in self.kpi_dic.items():
                    if value > self.threshold:
                        slack_messge.append('{} : {}'.format(key, value))
                for text in slack_messge:
                    message_to_be_send = message_to_be_send + text + "\n"
                print message_to_be_send
            message_to_be_send = self.os + "\n" + self.device_id + "\n" + message_to_be_send + "\n" + "Device_log url:" + log_url + "\n" + "Device screenshot url:" + png_url
            #slack alert
            self.alerts.slack_alert(message_to_be_send)
            #Mail Alert
            self.alerts.email_alert(message_to_be_send)

        self.driver.quit()

    def videoplay_check(self, sec):
        self.driver.implicitly_wait(5)
        t_end = time.time() + sec
        while time.time() < t_end:
            try:
                sleep(5)
                self.driver.tap([(105, 181)])
                player_control = self.driver.find_element_by_accessibility_id(
                    "PlayPauseButton")
            except:
                spinner = self.driver.find_element_by_name("spinner")
                print "Video Interrupted"
                self.video_play()

    def video_play(self):
        self.driver.implicitly_wait(30)
        t_end = time.time() + 10
        cmd = shlex.split("idevicesyslog -u  %s" % self.device_id)
        process = subprocess.Popen(cmd, stdout=subprocess.PIPE)

        for line in iter(process.stdout.readline, b''):
            if "FigStreamPlayer" in line:
                print "VideoPlayed"
                video_end = int(round(time.time() * 1000))
                break
            if time.time() > t_end_ad:
                break
        process.kill()

    def delete_download(self):
        self.driver.implicitly_wait(6)
        try:
            downloads_tab = self.driver.find_element_by_name("Downloads")
            downloads_tab.click()
            sleep(5)
            edit_button = self.driver.find_element_by_accessibility_id(
                "Editar")
            edit_button.click()
            check_box = self.driver.find_element_by_class_name(
                "XCUIElementTypeCell").find_element_by_class_name(
                    "XCUIElementTypeButton")
            check_box.click()
            conf_del = self.driver.find_element_by_accessibility_id("Apagar")
            conf_del.click()
        except:
            pass

    def test_login(self):
        self.driver.implicitly_wait(60)

        #Launching app
        agora_tab = self.driver.find_element_by_name("Agora")
        launched_app = int(round(time.time() * 1000))

        #calcualting launch time
        self.app_launch_time = launched_app - self.start_app
        print("App Launch Time is %s ms" % self.app_launch_time)
        d = {'globo_launch_time': self.app_launch_time}
        self.kpi_dic.update(d)
        #incrementing pass count
        self.pass_count += 1
        sleep(3)

        self.delete_download()
        self.driver.implicitly_wait(60)
        home_tab = self.driver.find_element_by_name("Início")
        home_tab.click()

        #login
        self.status = "Fail_login"
        screen_size = self.driver.get_window_size()
        width = screen_size['width']
        height = screen_size['height']
        tap_x = width * 0.956
        tap_y = height * 0.042

        #profile_button tap
        self.driver.tap([(tap_x, tap_y)])

        #logout
        try:
            self.driver.implicitly_wait(5)
            logout_button = self.driver.find_element_by_name("Sair")
            logout_button.click()
            confirm_button = self.driver.find_element_by_name("Sim")
            confirm_button.click()
            self.driver.find_element_by_class_name(
                "XCUIElementTypeNavigationBar")
            sleep(2)
        except:
            pass

        self.driver.tap([(tap_x, tap_y)])
        self.driver.implicitly_wait(30)
        entrar = self.driver.find_element_by_name("Entrar")
        entrar.click()

        email_id = self.driver.find_element_by_name("e-mail")
        email_id.click()
        email_id.set_value('laurent_headspin')

        password = self.driver.find_element_by_name("senha")
        password.click()
        password.set_value('Globo@321')

        login_button = self.driver.find_element_by_name("ENTRAR")
        login_button.click()

        self.status = "Fail_page_load_post_login"

        self.driver.find_element_by_name("Sair")
        sleep(2)
        close_x_tap = width * 0.813
        close_y_tap = height * 0.220

        self.driver.tap([(close_x_tap, close_y_tap)])

        start_login = int(round(time.time() * 1000))
        home_button = self.driver.find_element_by_name("Agora")
        self.driver.find_element_by_class_name("XCUIElementTypeImage")
        end_login = int(round(time.time() * 1000))

        self.home_pg_load_time = end_login - start_login
        print("Home page loading time is %s ms" % self.home_pg_load_time)

        d = {'globo_post_login_home_load_time': self.home_pg_load_time}
        self.kpi_dic.update(d)

        self.pass_count = self.pass_count + 1
        sleep(5)

        categories = self.driver.find_element_by_name("Categorias")
        categories.click()
        sleep(4)
        novelas = self.driver.find_element_by_name("Novelas")
        novelas.click()
        sleep(4)

        screen_size = self.driver.get_window_size()
        width = screen_size['width']
        height = screen_size['height']

        swipe_start_x = width / 2
        swipe_start_y = height * 0.6
        swipe_end_x = width / 2
        swipe_end_y = height * 0.2

        sleep(4)
        seed(time.time())
        for i in range(0, randint(0, 4)):
            self.driver.swipe(swipe_start_x, swipe_start_y, swipe_end_x,
                              swipe_end_y, 1000)
        seed(time.time()**2)

        selector = "type == 'XCUIElementTypeStaticText' AND visible == 1"
        title_buttons = self.driver.find_elements_by_ios_predicate(selector)
        title_button = title_buttons[randint(0, 5)]
        sleep(5)

        location = title_button.location
        size = title_button.size
        self.x_tap = location['x'] + int(size['width'] / 2)
        self.y_tap = location['y'] + int(size['height'] / 2)
        self.driver.tap([(self.x_tap, self.y_tap)])

        self.driver.implicitly_wait(15)
        try:
            self.driver.find_element_by_accessibility_id(
                "titleHighlightViewCellTitleName")
        except:
            tap_x = width * 0.4
            tap_y = height * 0.6
            self.driver.tap([(tap_x, tap_y)])
            self.driver.find_element_by_accessibility_id(
                "titleHighlightViewCellTitleName")

        sleep(5)
        title_name = self.driver.find_element_by_accessibility_id(
            "titleHighlightViewCellTitleName")
        get_title_name = title_name.text.lower().encode('utf-8')
        title_name = str(get_title_name)

        self.driver.implicitly_wait(10)
        try:
            thumb_button = self.driver.find_elements_by_class_name(
                "XCUIElementTypeCollectionView"
            )[0].find_elements_by_class_name("XCUIElementTypeButton")[0]
            thumb_button.click()
            sleep(2)
        except:
            pass

        self.status = "Fail_video_play"

        try:
            continue_button = self.driver.find_element_by_name(
                "titleHighlightViewCellFirstButton")
        except:
            pass
        sleep(4)
        try:
            continue_button.click()
        except:
            con_x = width * 0.13
            con_y = height * 0.295
            self.driver.tap([(con_x, con_y)])

        video_start = int(round(time.time() * 1000))
        t_end_ad = time.time() + 60
        cmd = shlex.split("idevicesyslog -u  %s" % self.device_id)
        process = subprocess.Popen(cmd, stdout=subprocess.PIPE)

        for line in iter(process.stdout.readline, b''):
            if "FigStreamPlayer" in line:
                print "VideoPlayed"
                video_end = int(round(time.time() * 1000))
                break
            if time.time() > t_end_ad:
                break
        process.kill()
        self.video_load_time = video_end - video_start

        self.driver.implicitly_wait(5)
        try:
            oops_button = self.driver.find_element_by_name("OK")
            oops_button.click()
            sleep(2)
            self.driver.tap([(con_x, con_y)])

            video_second = int(round(time.time() * 1000))
            t_end_ad = time.time() + 60
            cmd = shlex.split("idevicesyslog -u  %s" % self.device_id)
            process = subprocess.Popen(cmd, stdout=subprocess.PIPE)

            for line in iter(process.stdout.readline, b''):
                if "FigStreamPlayer" in line:
                    print "VideoPlayed"
                    video_play = int(round(time.time() * 1000))
                    break
                if time.time() > t_end_ad:
                    break
            process.kill()
            self.video_load_time = video_play - video_second
        except:
            pass

        print "Video load time ", self.video_load_time
        d = {'globo_video_load_time': self.video_load_time}
        self.kpi_dic.update(d)
        sleep(5)
        self.pass_count = self.pass_count + 1

        #Watch the Video for 1 minute
        self.videoplay_check(30)
        self.driver.implicitly_wait(10)

        screen_size = self.driver.get_window_size()
        width = screen_size['width']
        height = screen_size['height']
        swipe_start_x = width / 2
        swipe_start_y = height * 0.7
        swipe_end_x = width / 2
        swipe_end_y = height * 0.3

        try:
            potential_download_buttons = self.driver.find_elements_by_accessibility_id(
                "")
            flag = 0
            for j in potential_download_buttons:
                if j.size['height'] >= 22 and j.size['height'] <= 28:
                    download_button = j
                    flag = 1
                    break
                if flag == 1:
                    break
            sleep(5)

            download_button.click()
        except:
            tap_x = width * 0.116
            tap_y = height * 0.631
            self.driver.tap([(tap_x, tap_y)])

        start_download = int(round(time.time() * 1000))

        t_end = time.time() + 50
        self.driver.implicitly_wait(3)
        self.status = "Fail_Download"
        downloads_tab = self.driver.find_element_by_accessibility_id(
            "Downloads")
        downloads_tab.click()
        try:
            dont_cancel_download = self.driver.find_element_by_accessibility_id(
                "Não")
            dont_cancel_download.click()
            downloads_tab = self.driver.find_element_by_accessibility_id(
                "Downloads")
            downloads_tab.click()
        except:
            pass
        sleep(5)

        self.driver.implicitly_wait(50)
        download_title_name = self.driver.find_elements_by_class_name(
            "XCUIElementTypeCell")[0].find_elements_by_class_name(
                "XCUIElementTypeStaticText")[2].get_attribute("name")
        download_title = download_title_name.lower().encode("utf-8")
        download_title_name = str(download_title)
        print download_title_name
        if download_title_name == title_name:
            print "Title Added to list"
            self.title_check = True
            self.pass_count = self.pass_count + 1

        self.driver.implicitly_wait(5)
        t_end = time.time() + 1200
        while time.time() < t_end:
            try:
                download_bar = self.driver.find_element_by_accessibility_id(
                    "1 download em andamento")
            except:
                end_download = int(round(time.time() * 1000))
                break

        sleep(4)
        self.download_time = end_download - start_download
        print "Download time:  ", self.download_time
        self.pass_count = self.pass_count + 1
        d = {'Download_time': self.download_time}
        self.kpi_dic.update(d)

        self.driver.implicitly_wait(50)
        self.delete_download()
        sleep(5)

        if self.title_check == False:
            self.status = "Fail_title_check"
        else:
            self.status = "Pass"
Ejemplo n.º 4
0
class SimpleAndroidTests(unittest.TestCase):

    #check if the necessary folders are present, if not create
    def check_dir(self, dir_path):
        if not os.path.isdir(dir_path):
            print "Creating the log dir"
            os.mkdir(dir_path)

    def adb_dump_data(self, udid, reference, step, adb_dump_dir):

        #save teh sys dump of the phone
        self.adb_activities.get_dumpsys(udid, reference, step, adb_dump_dir)

        #Get the cpu info
        cpu_usage = self.adb_activities.get_cpuinfo(udid)

        #Get mem info
        mem_usage = self.adb_activities.get_mem_info(udid, self.package)

        #Device temp
        temperature = self.adb_activities.get_device_temp(udid)

        print step, cpu_usage, mem_usage, temperature
        return [step, cpu_usage, mem_usage, temperature]

    def setUp(self):

        self.reference = str(int(round(time.time() * 1000)))
        self.package = "com.globo.globotv"

        #device id as 1st argument
        self.udid = sys.argv[1]
        self.os = 'Android'

        #logs folder
        self.logs_dir = os.getcwd() + "/logs"
        print self.logs_dir
        self.check_dir(self.logs_dir)
        self.logs_dir = self.logs_dir + "/" + self.reference
        os.mkdir(self.logs_dir)

        #adb_dump folder
        self.adb_dump_dir = os.getcwd() + "/adb_dump"
        self.check_dir(self.adb_dump_dir)
        self.adb_dump_dir = self.adb_dump_dir + "/" + self.reference
        os.mkdir(self.adb_dump_dir)

        self.adb_activities = AdbDdata()
        self.alerts = SendAlert()
        self.array_of_data_list = []

        #Befre test function
        self.adb_activities.before_test(self.udid)
        self.capture_cap = sys.argv[3]

        #desired caps for the app
        desired_caps = {}
        desired_caps['platformName'] = self.os
        desired_caps['udid'] = self.udid
        desired_caps['deviceName'] = self.udid
        desired_caps['appPackage'] = self.package
        desired_caps['appActivity'] = "com.globo.globotv.splash.SplashActivity"
        desired_caps['noReset'] = True
        desired_caps['automationName'] = "uiautomator2"
        desired_caps['newCommandTimeout'] = 600
        if self.capture_cap == "1":
            desired_caps['headspin.capture'] = True
        else:
            desired_caps['headspin.capture'] = False
        desired_caps['no-reset'] = True

        appium_input = sys.argv[2]
        if appium_input.isdigit():
            self.url = ('http://127.0.0.1:' + appium_input + '/wd/hub')
        else:
            self.url = appium_input

        #launching app
        self.driver = webdriver.Remote(self.url, desired_caps)

        self.start_app = int(round(time.time() * 1000))

        #initialising variables
        self.status = "Fail_launch"
        self.app_launch_time = 0

        self.status_dic = {}
        self.kpi_dic = {}

        self.app_launch_time = 0
        self.home_pg_load_time = 0
        self.initial_video_play = 0
        self.sub_video_play = 0
        self.title_check = False
        self.progress_check = False
        self.test_name = "Continue_Assistindo"
        self.kpi_count = 6
        self.pass_count = 0
        self.fail_count = 0

    def tearDown(self):

        #incrementing kpi count
        print "Pass count is %s" % self.pass_count
        if self.pass_count != self.kpi_count:
            self.fail_count = self.kpi_count - self.pass_count
        else:
            self.fail_count = 0
        print "Fail count is %s " % self.fail_count

        #After function
        self.adb_activities.after_test(self.udid, self.reference, self.driver,
                                       self.status)
        if self.capture_cap == "1":
            self.session_id = self.driver.session_id
            print self.session_id
        else:
            self.session_id = None

    #Insert to app table
        insert = MysqlDataInsert()
        insert.globo_continuar_metrics(
            self.driver, self.app_launch_time, self.home_pg_load_time,
            self.initial_video_play, self.title_check, self.progress_check,
            self.sub_video_play, self.pass_count, self.fail_count, self.status,
            self.reference, self.session_id, self.test_name)

        path = os.getcwd() + "/logs/"

        if self.status == "Pass":
            screenshot_name = str(self.reference) + '_' + self.udid + ".png"
            log_file_name = str(self.reference) + '_' + self.udid + ".log"
        else:
            log_file_name = str(
                self.reference) + '_' + self.udid + "_error.log"
            screenshot_name = str(
                self.reference) + '_' + self.udid + "_error.png"

        screenshot_path = path + "/" + screenshot_name

        log_path = path + "/" + log_file_name

        log_url = "https://s3-us-west-2.amazonaws.com/grafana-images.headspin.io/globo/" + log_file_name
        png_url = "https://s3-us-west-2.amazonaws.com/grafana-images.headspin.io/globo/" + screenshot_name

        self.threshold = 5000
        if not all(
                i < self.threshold
                for i in list(self.kpi_dic.values())) or self.status != "Pass":
            slack_messge = []
            message_to_be_send = ""
            if not all(i < self.threshold
                       for i in list(self.kpi_dic.values())):

                for key, value in self.kpi_dic.items():
                    if value > self.threshold:
                        slack_messge.append('{} : {}'.format(key, value))
                for text in slack_messge:
                    message_to_be_send = message_to_be_send + text + "\n"
                print message_to_be_send

            message_to_be_send = self.os + "\n" + self.udid + "\n" + message_to_be_send + "\n" + "Device_log url:" + log_url + "\n" + "Device screenshot url:" + png_url

            #slack alert
            self.alerts.slack_alert(message_to_be_send)

            #Mail ALert
            self.alerts.email_alert(message_to_be_send)

        self.driver.quit()

    def videoplay_check(self, sec):
        self.driver.implicitly_wait(5)
        t_end = time.time() + sec
        while time.time() < t_end:
            try:
                screen_size = self.driver.get_window_size()
                width = screen_size['width']
                height = screen_size['height']
                tap_x = width * 0.5
                tap_y = height * 0.23
                self.driver.tap([(tap_x, tap_y)])
                player_control = self.driver.find_element_by_id(
                    "com.globo.globotv:id/media_control")
                sleep(5)
            except:
                spinner = self.driver.find_element_by_id(
                    'com.globo.globotv:id/progress_bar')
                print "Video Interrupted"
                self.video_play()

    def video_play(self):
        self.driver.implicitly_wait(1)
        t_end = time.time() + 10
        while time.time() < t_end:
            try:
                spinner = self.driver.find_element_by_id(
                    'com.globo.globotv:id/progress_bar')
                print "Spinner!!"
            except:
                break

    def test_login(self):

        self.driver.implicitly_wait(60)
        #Launching app
        agora_tab = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().description("Agora")')
        launched_app = int(round(time.time() * 1000))

        #calcualting launch time
        self.app_launch_time = launched_app - self.start_app
        print("App Launch Time is %s ms" % self.app_launch_time)
        d = {'globo_launch_time': self.app_launch_time}
        self.kpi_dic.update(d)
        #incrementing pass count
        self.pass_count += 1

        #library tab view time
        self.status = "Fail_login"
        user_icon = self.driver.find_element_by_id(
            "com.globo.globotv:id/menu_profile_custom_view_profile")
        user_icon.click()

        #Log out
        try:
            self.driver.implicitly_wait(5)
            logout = self.driver.find_element_by_android_uiautomator(
                'new UiSelector().text("Sair")')
            logout.click()
            #Confirm log out
            yes_btn = self.driver.find_element_by_id('android:id/button1')
            yes_btn.click()
            #Click on te account button
            self.driver.implicitly_wait(10)
            user_icon = self.driver.find_element_by_id(
                "com.globo.globotv:id/menu_profile_custom_view_profile")
            user_icon.click()
        except:
            pass

        self.driver.implicitly_wait(10)
        try:
            entrar = self.driver.find_element_by_id(
                'com.globo.globotv:id/activity_profile_text_view_get_int')
            entrar.click()
        except:
            user_icon = self.driver.find_element_by_id(
                "com.globo.globotv:id/menu_profile_custom_view_profile")
            user_icon.click()
            entrar = self.driver.find_element_by_id(
                'com.globo.globotv:id/activity_profile_text_view_get_int')
            entrar.click()

        self.driver.implicitly_wait(10)
        try:
            none_of_the_above = self.driver.find_element_by_id(
                "com.google.android.gms:id/cancel")
            none_of_the_above.click()
        except:
            pass
        sleep(5)
        self.driver.implicitly_wait(60)
        email_id_tf = self.driver.find_element_by_class_name(
            'android.widget.EditText')
        email_id_tf.set_value('laurent_headspin')

        #password
        password_tf = self.driver.find_elements_by_class_name(
            'android.widget.EditText')[1]
        password_tf.set_value('Globo@321')

        sleep(5)
        button = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().text("ENTRAR")')
        location = button.location
        size = button.size
        self.x_tap = location['x'] + int(size['width'] / 2)
        self.y_tap = location['y'] + int(size['height'] / 2)
        sleep(2)
        self.driver.tap([(self.x_tap, self.y_tap)])

        self.status = "Fail_page_load_post_login"
        back_btn = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().description("Navigate up")')
        back_btn.click()
        home_page_load_start = int(round(time.time() * 1000))
        self.driver.implicitly_wait(0.5)
        t_end = time.time() + 60
        while time.time() < t_end:
            try:
                self.driver.find_element_by_class_name(
                    'android.widget.ProgressBar')
            except:
                break

        self.driver.implicitly_wait(50)
        home_page = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().description("Agora")')
        home_page_load_end = int(round(time.time() * 1000))
        self.home_pg_load_time = home_page_load_end - home_page_load_start
        d = {'globo_post_login_home_load_time': self.home_pg_load_time}
        self.kpi_dic.update(d)
        self.pass_count += 1
        print "Home page loading time ", self.home_pg_load_time

        sleep(4)
        #Choose a title from home page

        categories_tab = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().description("Categorias")')
        categories_tab.click()
        sleep(2)

        series = self.driver.find_elements_by_id(
            'com.globo.globotv:id/view_holder_categories_image_view_cover')[1]
        series.click()
        sleep(2)

        screen_size = self.driver.get_window_size()
        width = screen_size['width']
        height = screen_size['height']
        swipe_start_x = width / 2
        swipe_start_y = height * 0.7
        swipe_end_x = width / 2
        swipe_end_y = height * 0.3
        self.driver.implicitly_wait(5)
        self.driver.swipe(swipe_start_x, swipe_start_y, swipe_end_x,
                          swipe_end_y, 1000)
        while True:
            try:
                title_button = self.driver.find_element_by_id(
                    "com.globo.globotv:id/custom_view_title_image_view_poster")
                break
            except:
                self.driver.swipe(swipe_start_x, swipe_start_y, swipe_end_x,
                                  swipe_end_y, 1000)
                continue

        actions = TouchAction(self.driver)
        actions.tap(title_button).perform()
        self.driver.implicitly_wait(50)
        title_name = self.driver.find_element_by_id(
            "com.globo.globotv:id/activity_title_text_view_title")

        #title_encode = title_name.text.decode('iso-8859-1')
        #get_title_name = title_encode.encode('utf-8')
        get_title_name = title_name.text
        print get_title_name
        Details_tab = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().text("Detalhes")')
        Details_tab.click()
        Spec_headline1 = self.driver.find_element_by_id(
            'com.globo.globotv:id/fragment_title_details_text_view_specifications'
        ).text
        #        Spec_genres1 = self.driver.find_element_by_id('com.globo.globotv:id/fragment_title_details_text_view_subset').text
        Spec_country1 = self.driver.find_element_by_id(
            'com.globo.globotv:id/fragment_title_details_text_view_country'
        ).text
        sleep(2)
        play_button = self.driver.find_element_by_id(
            "com.globo.globotv:id/activity_title_button_one")
        play_button.click()
        self.status = "Fail_video_Play"
        video_start = int(round(time.time() * 1000))
        self.driver.implicitly_wait(1)
        t_end = time.time() + 60
        while time.time() < t_end:
            try:
                spinner = self.driver.find_element_by_id(
                    'com.globo.globotv:id/progress_bar')
                print "Spinner!!"
            except:
                print "Not displayed"
                break

        self.driver.implicitly_wait(1)
        t_end = time.time() + 60
        while time.time() < t_end:
            try:
                spinner = self.driver.find_element_by_id(
                    'com.globo.globotv:id/progress_bar')
                print "Spinner!!"
            except:
                video_end = int(round(time.time() * 1000))
                print "Not displayed"
                break
        self.initial_video_play = video_end - video_start
        self.driver.implicitly_wait(5)
        try:
            self.driver.find_element_by_id("android:id/button1").click()
            sleep(2)
            play_button.click()
            video_second = int(round(time.time() * 1000))
            self.driver.implicitly_wait(1)
            t_end = time.time() + 60
            while time.time() < t_end:
                try:
                    spinner = self.driver.find_element_by_id(
                        'com.globo.globotv:id/progress_bar')
                    print "Spinner!!"
                except:
                    print "Not displayed"
                    break

            self.driver.implicitly_wait(1)
            t_end = time.time() + 60
            while time.time() < t_end:
                try:
                    spinner = self.driver.find_element_by_id(
                        'com.globo.globotv:id/progress_bar')
                    print "Spinner!!"
                except:
                    video_play = int(round(time.time() * 1000))
                    print "Not displayed"
                    break
            self.initial_video_play = video_play - video_second
        except:
            pass

        print "Initial Video load time ", self.initial_video_play
        self.pass_count += 1
        d = {'globo_initial_play': self.initial_video_play}

        self.kpi_dic.update(d)
        #Watch the Video for 1 minute
        self.videoplay_check(80)
        self.driver.implicitly_wait(50)

        navigate_up = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().descriptionContains("Navigate up")')
        navigate_up.click()

        self.status = "Fail_get_progress"
        get_title_progress = self.driver.find_element_by_id(
            "com.globo.globotv:id/activity_title_progress").text
        print get_title_progress

        sleep(2)
        navigate_up = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().descriptionContains("Navigate up")')
        navigate_up.click()

        #closing and relaunching app
        self.driver.close_app()
        sleep(10)
        self.driver.launch_app()

        #App relaunched

        #Searching for the same title
        search_button = self.driver.find_element_by_id(
            "com.globo.globotv:id/menu_bottom_navigation_view_item_search")
        search_button.click()

        search_bar = self.driver.find_element_by_id(
            "com.globo.globotv:id/search_src_text")
        search_bar.click()
        search_bar.send_keys(get_title_name)
        self.driver.press_keycode(66)
        i = 0
        while i < len(
                self.driver.find_elements_by_id(
                    "com.globo.globotv:id/view_holder_custom_view_rails_custom_view_title"
                )):
            title_select = self.driver.find_elements_by_id(
                "com.globo.globotv:id/view_holder_custom_view_rails_custom_view_title"
            )[i]
            title_select.click()

            self.status = "Fail_title_check"
            self.title_check = False
            search_title = self.driver.find_element_by_id(
                "com.globo.globotv:id/activity_title_text_view_title")
            search_title_name = search_title.text
            print search_title_name
            Details_tab = self.driver.find_element_by_android_uiautomator(
                'new UiSelector().text("Detalhes")')
            Details_tab.click()
            Spec_headline2 = self.driver.find_element_by_id(
                'com.globo.globotv:id/fragment_title_details_text_view_specifications'
            ).text
            #Spec_genres2 = self.driver.find_element_by_id('com.globo.globotv:id/fragment_title_details_text_view_subset').text
            Spec_country2 = self.driver.find_element_by_id(
                'com.globo.globotv:id/fragment_title_details_text_view_country'
            ).text

            if (search_title_name == get_title_name) and (
                    Spec_headline1 == Spec_headline2) and (Spec_country1
                                                           == Spec_country2):
                print "Title found"
                self.title_check = True
                self.pass_count = self.pass_count + 1
                break
            else:
                i += 1
                navigate_up = self.driver.find_element_by_android_uiautomator(
                    'new UiSelector().descriptionContains("Navigate up")')
                navigate_up.click()

        sleep(2)
        self.status = "Fail_progress_check"
        self.progress_check = False
        search_title_progress = self.driver.find_element_by_id(
            "com.globo.globotv:id/activity_title_progress")
        search_title_progress = search_title_progress.text
        print search_title_progress
        if search_title_progress == get_title_progress:
            print "Progress time verified"
            self.progress_check = True
            self.pass_count = self.pass_count + 1

        continue_button = self.driver.find_element_by_id(
            "com.globo.globotv:id/activity_title_button_one")
        continue_button.click()

        sub_start = int(round(time.time() * 1000))
        self.driver.implicitly_wait(1)
        t_end = time.time() + 60
        while time.time() < t_end:
            try:
                spinner = self.driver.find_element_by_id(
                    'com.globo.globotv:id/progress_bar')
                print "Spinner!!"
            except:
                print "Not displayed"
                break

        self.driver.implicitly_wait(1)
        t_end = time.time() + 60
        while time.time() < t_end:
            try:
                spinner = self.driver.find_element_by_id(
                    'com.globo.globotv:id/progress_bar')
                print "Spinner!!"
            except:
                sub_end = int(round(time.time() * 1000))
                print "Not displayed"
                break

        print " Video Resumed "
        self.sub_video_play = sub_end - sub_start
        print "subsequent video load time ", self.sub_video_play
        self.pass_count += 1
        sleep(10)
        if self.progress_check == False:
            self.status = "Fail_progress_check"
        elif self.title_check == False:
            self.status = "Fail_title_check"
        else:
            self.status = "Pass"
Ejemplo n.º 5
0
class Globo_1hour_video(unittest.TestCase):
    #check if the necessary folders are present, if not create
    def check_dir(self, dir_path):
        if not os.path.isdir(dir_path):
            print "Creating the log dir"
            os.mkdir(dir_path)

    def adb_dump_data(self, udid, reference, step, adb_dump_dir):
        #save the sys dump of the phone
        self.adb_activities.get_dumpsys(udid, reference, step, adb_dump_dir)
        #Get the cpu info
        cpu_usage = self.adb_activities.get_cpuinfo(udid)
        #Get mem info
        mem_usage = self.adb_activities.get_mem_info(udid, self.package)
        #Device temp
        temperature = self.adb_activities.get_device_temp(udid)
        print step, cpu_usage, mem_usage, temperature
        return [step, cpu_usage, mem_usage, temperature]

    def setUp(self):
        self.reference = str(int(round(time.time() * 1000)))
        self.package = "com.globo.globotv"
        #device id as 1st argument
        self.udid = sys.argv[1]
        self.os = 'Android'
        #logs folder
        self.logs_dir = os.getcwd() + "/logs"
        print self.logs_dir
        self.check_dir(self.logs_dir)
        self.logs_dir = self.logs_dir + "/" + self.reference
        os.mkdir(self.logs_dir)
        #adb_dump folder
        self.adb_dump_dir = os.getcwd() + "/adb_dump"
        self.check_dir(self.adb_dump_dir)
        self.adb_dump_dir = self.adb_dump_dir + "/" + self.reference
        os.mkdir(self.adb_dump_dir)
        self.adb_activities = AdbDdata()
        self.alerts = SendAlert()
        self.array_of_data_list = []
        #Before test function
        self.adb_activities.before_test(self.udid)
        self.capture_cap = sys.argv[3]
        #desired caps for the app
        desired_caps = {}
        desired_caps['platformName'] = self.os
        desired_caps['udid'] = self.udid
        desired_caps['deviceName'] = self.udid
        desired_caps['appPackage'] = self.package
        desired_caps['appActivity'] = "com.globo.globotv.splash.SplashActivity"
        desired_caps['noReset'] = True
        desired_caps['automationName'] = "uiautomator2"
        desired_caps['newCommandTimeout'] = 1200
        if self.capture_cap == "1":
            desired_caps['headspin:capture.video'] = True
        else:
            desired_caps['headspin:capture.video'] = False
        desired_caps['no-reset'] = True
        appium_input = sys.argv[2]
        if appium_input.isdigit():
            self.url = ('http://127.0.0.1:' + appium_input + '/wd/hub')
        else:
            self.url = appium_input
        #launching app
        self.driver = webdriver.Remote(self.url, desired_caps)
        self.start_app = int(round(time.time() * 1000))
        #initialising variables
        self.status = "Fail_launch"
        self.app_launch_time = 0
        self.status_dic = {}
        self.kpi_dic = {}
        self.app_launch_time = 0
        self.home_pg_load_time = 0
        self.cinema_load_time = 0
        self.video_load_time = 0
        self.alerts_during_video_play = False
        self.buffer_count = 0
        self.alert_count = 0
        self.test_name = "Globo_1hour_video"
        self.kpi_count = 5
        self.pass_count = 0
        self.fail_count = 0

    def tearDown(self):
        #incrementing kpi count
        print "Pass count is %s" % self.pass_count
        if self.pass_count != self.kpi_count:
            self.fail_count = self.kpi_count - self.pass_count
        else:
            self.fail_count = 0
        print "Fail count is %s " % self.fail_count
        #After function
        self.adb_activities.after_test(self.udid, self.reference, self.driver,
                                       self.status)
        if self.capture_cap == "1":
            self.session_id = self.driver.session_id
            print self.session_id
        else:
            self.session_id = None
        #Insert to app table
        insert = MysqlDataInsert()
        insert.globo_1hour_video_metrics(
            self.driver, self.app_launch_time, self.home_pg_load_time,
            self.cinema_load_time, self.video_load_time,
            self.alerts_during_video_play, self.buffer_count, self.alert_count,
            self.pass_count, self.fail_count, self.status, self.reference,
            self.session_id, self.test_name)
        path = os.getcwd() + "/logs/"
        if self.status == "Pass":
            screenshot_name = str(self.reference) + '_' + self.udid + ".png"
            log_file_name = str(self.reference) + '_' + self.udid + ".log"
        else:
            log_file_name = str(
                self.reference) + '_' + self.udid + "_error.log"
            screenshot_name = str(
                self.reference) + '_' + self.udid + "_error.png"
        screenshot_path = path + "/" + screenshot_name
        log_path = path + "/" + log_file_name
        log_url = "https://s3-us-west-2.amazonaws.com/grafana-images.headspin.io/globo/" + log_file_name
        png_url = "https://s3-us-west-2.amazonaws.com/grafana-images.headspin.io/globo/" + screenshot_name
        self.threshold = 5000
        if not all(
                i < self.threshold
                for i in list(self.kpi_dic.values())) or self.status != "Pass":
            slack_messge = []
            message_to_be_send = ""
            if not all(i < self.threshold
                       for i in list(self.kpi_dic.values())):
                for key, value in self.kpi_dic.items():
                    if value > self.threshold:
                        slack_messge.append('{} : {}'.format(key, value))
                        for text in slack_messge:
                            message_to_be_send = message_to_be_send + text + "\n"
                            print message_to_be_send
            message_to_be_send = self.os + "\n" + self.udid + "\n" + message_to_be_send + "\n" + "Device_log url:" + log_url + "\n" + "Device screenshot url:" + png_url
            #slack alert
            self.alerts.slack_alert(message_to_be_send)
            #Mail Alert
            self.alerts.email_alert(message_to_be_send)
        self.driver.quit()

    def test_login(self):
        self.driver.implicitly_wait(60)
        #Launching app
        agora_tab = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().description("Agora")')
        launched_app = int(round(time.time() * 1000))
        #calcualting launch time
        self.app_launch_time = launched_app - self.start_app
        print("App Launch Time is %s ms" % self.app_launch_time)
        d = {'globo_launch_time': self.app_launch_time}
        self.kpi_dic.update(d)
        #incrementing pass count
        self.pass_count += 1
        sleep(5)
        #library tab view time
        self.status = "Fail_login"
        user_icon = self.driver.find_element_by_id(
            "com.globo.globotv:id/menu_profile_custom_view_profile")
        user_icon.click()
        sleep(5)
        #Log out
        try:
            self.driver.implicitly_wait(5)
            logout = self.driver.find_element_by_android_uiautomator(
                'new UiSelector().text("Sair")')
            logout.click()
            sleep(2)
            #Confirm log out
            yes_btn = self.driver.find_element_by_id('android:id/button1')
            yes_btn.click()
            sleep(5)
            #Click on te account button
            self.driver.implicitly_wait(10)
            user_icon = self.driver.find_element_by_id(
                "com.globo.globotv:id/menu_profile_custom_view_profile")
            user_icon.click()
            sleep(5)
        except:
            pass
        self.driver.implicitly_wait(60)
        entrar = self.driver.find_element_by_id(
            'com.globo.globotv:id/activity_profile_text_view_get_int')
        entrar.click()
        self.driver.implicitly_wait(10)
        try:
            none_of_the_above = self.driver.find_element_by_id(
                "com.google.android.gms:id/cancel")
            none_of_the_above.click()
        except:
            pass
        sleep(5)
        self.driver.implicitly_wait(60)
        email_id_tf = self.driver.find_element_by_class_name(
            'android.widget.EditText')
        email_id_tf.set_value('laurent_headspin')
        #password
        password_tf = self.driver.find_elements_by_class_name(
            'android.widget.EditText')[1]
        password_tf.set_value('Globo@321')
        sleep(5)
        button = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().text("ENTRAR")')
        location = button.location
        size = button.size
        self.x_tap = location['x'] + int(size['width'] / 2)
        self.y_tap = location['y'] + int(size['height'] / 2)
        sleep(2)
        self.driver.tap([(self.x_tap, self.y_tap)])
        self.status = "Fail_page_load_post_login"
        back_btn = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().description("Navigate up")')
        back_btn.click()
        home_page_load_start = int(round(time.time() * 1000))
        self.driver.implicitly_wait(0.5)
        t_end = time.time() + 60
        while time.time() < t_end:
            try:
                self.driver.find_element_by_class_name(
                    'android.widget.ProgressBar')
            except:
                break
        home_page = self.driver.find_element_by_id(
            "com.globo.globotv:id/custom_view_premium_highlights_image_view_background"
        )
        home_page_load_end = int(round(time.time() * 1000))
        self.home_pg_load_time = home_page_load_end - home_page_load_start
        d = {'globo_post_login_home_load_time': self.home_pg_load_time}
        self.kpi_dic.update(d)
        self.pass_count += 1
        print "Home page loading time ", self.home_pg_load_time
        sleep(5)
        self.driver.implicitly_wait(60)
        categories_tab = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().description("Categorias")')
        categories_tab.click()
        sleep(5)
        cinema = self.driver.find_elements_by_id(
            'com.globo.globotv:id/view_holder_categories_image_view_cover')[2]
        cinema.click()
        sleep(5)
        first_poster = self.driver.find_elements_by_id(
            'com.globo.globotv:id/custom_view_title_image_view_poster')[0]
        first_poster.click()
        cinema_load_start = int(round(time.time() * 1000))
        title = self.driver.find_element_by_id(
            'com.globo.globotv:id/activity_title_text_view_title')
        cinema_load_end = int(round(time.time() * 1000))
        self.cinema_load_time = cinema_load_end - cinema_load_start
        self.pass_count += 1
        d = {'globo_cinema_page_load_time': self.cinema_load_time}
        self.kpi_dic.update(d)
        print "Cinema load time", self.cinema_load_time
        self.status = "Fail_video_play_start"
        continue_btn = self.driver.find_element_by_id(
            'com.globo.globotv:id/activity_title_button_one')
        continue_btn.click()
        video_start = int(round(time.time() * 1000))
        self.driver.implicitly_wait(1)
        try:
            self.driver.find_element_by_id("android:id/button1").click()
            sleep(2)
            play_button = self.driver.find_element_by_id(
                "com.globo.globotv:id/activity_title_button_one")
            play_button.click()
            video_second = int(round(time.time() * 1000))
            self.driver.implicitly_wait(1)
            t_end = time.time() + 10
            while time.time() < t_end:
                try:
                    spinner = self.driver.find_element_by_id(
                        'com.globo.globotv:id/progress_bar')
                    print "Spinner!!"
                except:
                    video_play = int(round(time.time() * 1000))
                    print "Not displayed"
                    break
            self.video_load_time = video_play - video_second
        except:
            t_end = time.time() + 10
            while time.time() < t_end:
                try:
                    spinner = self.driver.find_element_by_id(
                        'com.globo.globotv:id/progress_bar')
                    print "Spinner!!"
                except:
                    video_end = int(round(time.time() * 1000))
                    print "Not displayed"
                    break
            self.video_load_time = video_end - video_start
        self.driver.implicitly_wait(5)

        print("Video load time ", self.video_load_time)
        self.pass_count += 1
        d = {'globo_video_load_time': self.video_load_time}
        self.kpi_dic.update(d)
        buffer_flag = False
        sleep(5)
        t_end = time.time() + 3600
        while time.time() < t_end:
            self.driver.implicitly_wait(1)
            try:
                spinner = self.driver.find_element_by_id(
                    'com.globo.globotv:id/progress_bar')
                if buffer_flag == False:
                    buffer_flag = True
                    self.buffer_count += 1
            except:
                buffer_flag = False
                pass
            self.driver.implicitly_wait(0.5)
            try:
                flag = 0
                try:
                    alert = self.driver.find_element_by_android_uiautomator(
                        'new UiSelector().textContains("OK")')
                    flag = 1
                except:
                    pass
                if flag == 0:
                    try:
                        alert = self.driver.find_element_by_android_uiautomator(
                            'new UiSelector().textContains("Ok")')
                        flag = 2
                    except expression as identifier:
                        pass
                if flag == 0:
                    try:
                        alert = self.driver.find_element_by_android_uiautomator(
                            'new UiSelector().textContains("ATUALIZAR")')
                        flag = 3
                    except:
                        pass
                alert.click()
                self.alerts_during_video_play = True
                self.alert_count += 1
                try:
                    self.driver.find_element_by_id(
                        "android:id/button1").click()
                except:
                    pass
                try:
                    continue_btn = self.driver.find_element_by_id(
                        'com.globo.globotv:id/activity_title_button_one')
                    continue_btn.click()
                    sleep(3)
                except:
                    pass
            except:
                pass
        if self.alerts_during_video_play:
            self.status = "Fail_video_interrupted_by_alerts"
        else:
            self.status = "Pass"
            self.pass_count += 1
Ejemplo n.º 6
0
class SimpleAndroidTests(unittest.TestCase):

    #check if the necessary folders are present, if not create
    def check_dir(self, dir_path):
        if not os.path.isdir(dir_path):
            print "Creating the log dir"
            os.mkdir(dir_path)

    def adb_dump_data(self, udid, reference, step, adb_dump_dir):

        #save teh sys dump of the phone
        self.adb_activities.get_dumpsys(udid, reference, step, adb_dump_dir)

        #Get the cpu info
        cpu_usage = self.adb_activities.get_cpuinfo(udid)

        #Get mem info
        mem_usage = self.adb_activities.get_mem_info(udid, self.package)

        #Device temp
        temperature = self.adb_activities.get_device_temp(udid)

        print step, cpu_usage, mem_usage, temperature
        return [step, cpu_usage, mem_usage, temperature]

    def setUp(self):

        self.reference = str(int(round(time.time() * 1000)))
        self.package = "com.globo.globotv"

        #device id as 1st argument
        self.udid = sys.argv[1]
        self.os = 'Android'

        #logs folder
        self.logs_dir = os.getcwd() + "/logs"
        print self.logs_dir
        self.check_dir(self.logs_dir)
        self.logs_dir = self.logs_dir + "/" + self.reference
        os.mkdir(self.logs_dir)

        #adb_dump folder
        self.adb_dump_dir = os.getcwd() + "/adb_dump"
        self.check_dir(self.adb_dump_dir)
        self.adb_dump_dir = self.adb_dump_dir + "/" + self.reference
        os.mkdir(self.adb_dump_dir)

        self.adb_activities = AdbDdata()
        self.alerts = SendAlert()
        self.array_of_data_list = []
        adb_data = self.adb_dump_data(self.udid, self.reference, "Before_Test",
                                      self.adb_dump_dir)
        self.array_of_data_list.append(adb_data)

        #Befre test function
        self.adb_activities.before_test(self.udid)
        self.capture_cap = sys.argv[3]

        #desired caps for the app
        desired_caps = {}
        desired_caps['platformName'] = self.os
        desired_caps['udid'] = self.udid
        desired_caps['deviceName'] = self.udid
        desired_caps['appPackage'] = self.package
        desired_caps['appActivity'] = "com.globo.globotv.splash.SplashActivity"
        desired_caps['noReset'] = True
        #	desired_caps['headspin:controlLock']= True
        desired_caps['automationName'] = "uiautomator2"
        desired_caps['newCommandTimeout'] = 600
        if self.capture_cap == "1":
            desired_caps['headspin:capture.video'] = True
            desired_caps['headspin:capture.network'] = False


#                desired_caps['headspin.capture'] = True
        else:
            desired_caps['headspin.capture'] = False
        desired_caps['no-reset'] = True

        #appium input as 2nd argument
        appium_input = sys.argv[2]
        if appium_input.isdigit():
            self.url = ('http://127.0.0.1:' + appium_input + '/wd/hub')
        else:
            self.url = appium_input

        #launching app
        self.driver = webdriver.Remote(self.url, desired_caps)

        self.start_app = int(round(time.time() * 1000))

        #initialising variables
        self.status = "Fail_launch"
        self.app_launch_time = 0

        self.status_dic = {}
        self.kpi_dic = {}

        self.app_launch_time = 0
        self.video_laod_time = 0
        self.download_start_time = 0
        self.dowload_check = False
        self.kpi_count = 4
        self.pass_count = 0
        self.fail_count = 0

    def tearDown(self):

        #incrementing kpi count
        print "Pass count is %s" % self.pass_count
        if self.pass_count != self.kpi_count:
            self.fail_count = self.kpi_count - self.pass_count
        else:
            self.fail_count = 0
        print "Fail count is %s " % self.fail_count

        #After function
        self.adb_activities.after_test(self.udid, self.reference, self.driver,
                                       self.status)
        if self.capture_cap == "1":
            self.session_id = self.driver.session_id
            print self.session_id
        else:
            self.session_id = None

    #Insert to app table
        insert = MysqlDataInsert()
        #        insert.globo_kpi_metrics(self.driver, self.app_launch_time, self.home_pg_load_time, self.series_load_time, self.video_laod_time, self.buffer_in_video, self.pass_count,self.fail_count,self.status,self.reference,self.session_id)

        path = os.getcwd() + "/logs/"

        if self.status == "Pass":
            screenshot_name = str(self.reference) + '_' + self.udid + ".png"
            log_file_name = str(self.reference) + '_' + self.udid + ".log"
        else:
            log_file_name = str(
                self.reference) + '_' + self.udid + "_error.log"
            screenshot_name = str(
                self.reference) + '_' + self.udid + "_error.png"

        screenshot_path = path + "/" + screenshot_name

        log_path = path + "/" + log_file_name

        log_url = "https://s3-us-west-2.amazonaws.com/grafana-images.headspin.io/globo/" + log_file_name
        png_url = "https://s3-us-west-2.amazonaws.com/grafana-images.headspin.io/globo/" + screenshot_name

        self.threshold = 5000
        if not all(
                i < self.threshold
                for i in list(self.kpi_dic.values())) or self.status != "Pass":
            slack_messge = []
            message_to_be_send = ""
            if not all(i < self.threshold
                       for i in list(self.kpi_dic.values())):

                for key, value in self.kpi_dic.items():
                    if value > self.threshold:
                        slack_messge.append('{} : {}'.format(key, value))
                for text in slack_messge:
                    message_to_be_send = message_to_be_send + text + "\n"
                print message_to_be_send

            message_to_be_send = self.os + "\n" + self.udid + "\n" + message_to_be_send + "\n" + "Device_log url:" + log_url + "\n" + "Device screenshot url:" + png_url

            #slack alert
            self.alerts.slack_alert(message_to_be_send)

            #Mail ALert
            self.alerts.email_alert(message_to_be_send)

        #data_list is [step,cpuinfo, meminfo, temp]
        adb_data = self.adb_dump_data(self.udid, self.reference, "After_Test",
                                      self.adb_dump_dir)
        self.array_of_data_list.append(adb_data)

        #data_list is [step,cpuinfo, meminfo, temp]
        for data_list in self.array_of_data_list:
            insert.globo_device_details(self.driver, data_list, self.status,
                                        self.reference)
        self.driver.quit()

    def test_login(self):

        self.driver.implicitly_wait(60)
        #Launching app
        home_page_image = self.driver.find_element_by_id(
            'com.globo.globotv:id/custom_view_premium_highlights_image_view_background'
        )
        launched_app = int(round(time.time() * 1000))

        #calcualting launch time
        self.app_launch_time = launched_app - self.start_app
        print("App Launch Time is %s ms" % self.app_launch_time)
        d = {'globo_launch_time': self.app_launch_time}
        self.kpi_dic.update(d)
        #incrementing pass count
        self.pass_count += 1

        categories_tab = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().text("Categorias")')
        categories_tab.click()

        novelas = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().text("Novelas")')
        novelas.click()

        first_poster = self.driver.find_elements_by_id(
            'com.globo.globotv:id/custom_view_title_image_view_poster')[0]
        first_poster.click()

        thumb = self.driver.find_element_by_id("com.globo.globotv:id/thumb")

        title = self.driver.find_element_by_id("com.globo.globotv:id/title")

        thumb = self.driver.find_element_by_id("com.globo.globotv:id/thumb")
        thumb.click()

        self.status = "Fail_video_play"

        self.driver.implicitly_wait(1)
        t_end = time.time() + 60
        video_start = int(round(time.time() * 1000))
        while time.time() < t_end:
            try:
                spinner = self.driver.find_element_by_id(
                    'com.globo.globotv:id/progress_bar')
                print "Spinner!!"
            except:
                print "Not displayed"
                break

        self.driver.implicitly_wait(1)
        t_end = time.time() + 60
        while time.time() < t_end:
            try:
                spinner = self.driver.find_element_by_id(
                    'com.globo.globotv:id/progress_bar')
                print "Spinner!!"
            except:
                print "Not displayed"
                break

        video_end = int(round(time.time() * 1000))

        self.video_laod_time = video_end - video_start
        print "Video load time ", self.video_laod_time
        self.pass_count += 1
        d = {'globo_video_load_time': self.video_laod_time}

        self.kpi_dic.update(d)

        sleep(5)

        self.status = "Fail_Download"
        donwload_button = self.driver.find_element_by_id(
            "com.globo.globotv:id/custom_view_download_status_content_root")
        donwload_button.click()

        start_download = int(round(time.time() * 1000))
        download_progress = self.driver.find_element_by_id(
            "com.globo.globotv:id/custom_view_download_status_status_progress_bar"
        )
        end_download = int(round(time.time() * 1000))

        self.download_start_time = end_download - start_download
        print " Download start time ", self.download_start_time
        self.pass_count += 1
        d = {'globo_download_start_time': self.download_start_time}

        self.kpi_dic.update(d)

        sleep(5)

        navigate_up = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().description("Navigate up")')
        navigate_up.click()

        sleep(3)
        self.status = "Fail_Download_Verify"

        download_tab = self.driver.find_element_by_android_uiautomator(
            'new UiSelector().text("Downloads")')
        download_tab.click()

        download_title = self.driver.find_element_by_id(
            "com.globo.globotv:id/view_holder_download_text_view_title")
        download_title.click()

        title_name = self.driver.find_element_by_id(
            "com.globo.globotv:id/custom_view_video_text_view_title")
        print "Title found on download list"
        self.dowload_check = True
        self.pass_count += 1

        sleep(2)
        progress = self.driver.find_element_by_id(
            "com.globo.globotv:id/custom_view_download_status_status_progress_bar"
        )
        progress.click()

        accept_button = self.driver.find_element_by_id("android:id/button1")
        accept_button.click()

        sleep(2)
        self.status = "Pass"
Ejemplo n.º 7
0
class Globo_Download_Content_Test(unittest.TestCase):
	
	def setUp(self):
		self.reference= str(int(round(time.time() * 1000)))
		self.package = "com.globo.globotv"
		#device id as 1st argument
		self.udid = sys.argv[1]
		self.os = 'Android'
	
		self.adb_activities= AdbDdata()
	        self.alerts = SendAlert()

        	#Befre test function
	        self.adb_activities.before_test(self.udid)

		self.capture_cap = sys.argv[3]
		#desired caps for the app
		desired_caps = {}
		desired_caps['platformName'] = self.os
		desired_caps['udid'] = self.udid
		desired_caps['deviceName'] = self.udid
		desired_caps['appPackage'] = self.package
		desired_caps['appActivity'] = "com.globo.globotv.splash.SplashActivity"
		desired_caps['noReset'] = True
		desired_caps['automationName'] = "uiautomator2"
		desired_caps['newCommandTimeout'] =600
		desired_caps['no-reset'] = True
		if self.capture_cap == "1":
            		desired_caps['headspin:capture'] = True
        	else:
            		desired_caps['headspin:capture'] = False
		appium_input= sys.argv[2]
		if appium_input.isdigit():
			self.url= ('http://127.0.0.1:' + appium_input + '/wd/hub')
		else:
			self.url= appium_input
		#launching app
		self.driver = webdriver.Remote(self.url, desired_caps)
		self.start_app = int(round(time.time() * 1000))
		#initialising variables
		self.status = "Fail_launch"
		self.app_launch_time= 0
		self.status_dic = {}
		self.kpi_dic= {}
		self.app_launch_time= 0
		self.home_pg_load_time = 0
		self.video_load_time = 0
		self.download_time = 0 
		self.title_check = False
		self.test_name = "Globo_Download_Content"
		self.kpi_count = 5
		self.pass_count = 0
		self.fail_count = 0

		self.title_name = ""
	
	def tearDown(self):		
		#incrementing kpi count
		print "Pass count is %s" %self.pass_count
		if self.pass_count!=self.kpi_count:
			self.fail_count = self.kpi_count - self.pass_count
		else:
			self.fail_count = 0
		print "Fail count is %s " %self.fail_count
	
		if self.capture_cap =="1":
                	self.session_id = self.driver.session_id
                	print self.session_id
        	else:
                	self.session_id = None	

		self.adb_activities.after_test(self.udid, self.reference, self.driver, self.status)
	
		insert = MysqlDataInsert()
	        insert.globo_download_content(self.driver, self.app_launch_time,self.home_pg_load_time, self.video_load_time, self.title_check,self.download_time, self.pass_count,self.fail_count,self.status,self.reference,self.session_id,self.test_name)
	

		path=os.getcwd()+ "/logs/"

	        if self.status=="Pass":
        	        screenshot_name = str(self.reference)+'_'+ self.udid +".png"
                	log_file_name = str(self.reference)+'_'+self.udid + ".log"
        	else:
                	log_file_name = str(self.reference)+'_'+self.udid + "_error.log"
                	screenshot_name = str(self.reference)+'_'+ self.udid +"_error.png"


	        screenshot_path = path+"/"+screenshot_name

        	log_path = path+"/"+ log_file_name

        	log_url = "https://s3-us-west-2.amazonaws.com/grafana-images.headspin.io/globo/"+log_file_name
        	png_url = "https://s3-us-west-2.amazonaws.com/grafana-images.headspin.io/globo/"+screenshot_name

		self.threshold= 5000
	        if not all( i< self.threshold for i in list(self.kpi_dic.values())) or self.status!= "Pass"  :
                        slack_messge= []
                        message_to_be_send=""
                        if not all( i< self.threshold for i in list(self.kpi_dic.values()) ):

                                for key,value in self.kpi_dic.items():
                                        if value>self.threshold:
                                                slack_messge.append('{} : {}'.format(key,value))
                                for text in slack_messge:
                                        message_to_be_send =  message_to_be_send+text+"\n"
                                print message_to_be_send

                        message_to_be_send = self.os+"\n"+self.udid+"\n"+message_to_be_send+"\n" +"Device_log url:"+log_url+"\n"+"Device screenshot url:"+png_url

                        #slack alert
                        self.alerts.slack_alert(message_to_be_send)

                        #Mail ALert
                        self.alerts.email_alert(message_to_be_send)
		self.driver.quit()
	
	
	def videoplay_check(self, sec):
		self.driver.implicitly_wait(5)
		t_end = time.time() + sec
		while time.time() < t_end:
			try:
				sleep(5)
				screen_size = self.driver.get_window_size()
				width = screen_size['width']
				height = screen_size['height']
				tap_x = width*0.4
				tap_y=height*0.23
				self.driver.tap([(tap_x,tap_y)])
				player_control = self.driver.find_element_by_id("com.globo.globotv:id/media_control")
			except:
				spinner = self.driver.find_element_by_id('com.globo.globotv:id/progress_bar')
				print "Video Interrupted"
				self.video_play()		
	
	def video_play(self):
		self.driver.implicitly_wait(1)
		t_end = time.time() + 10
		while time.time() < t_end:
			try:
				spinner = self.driver.find_element_by_id('com.globo.globotv:id/progress_bar')
			except:
				break		
	
	def delete_download(self):
		self.driver.implicitly_wait(6)
		try:
			downloads_tab = self.driver.find_element_by_android_uiautomator('new UiSelector().descriptionContains("Downloads")')
			downloads_tab.click()

			sleep(5)
			edit_button = self.driver.find_element_by_id("com.globo.globotv:id/menu_downloads_item_edit")
			edit_button.click()

			
			check_box = self.driver.find_elements_by_id("com.globo.globotv:id/view_holder_download_title_check_box_selected")
			for box in check_box:
				box.click()
				sleep(1)
	
			conf_del = self.driver.find_element_by_id("com.globo.globotv:id/snackbar_action")
			conf_del.click()
		except:
			pass
	
	#Select a random novela and check if it's downloadable. Else, searches and selects another random Novela
	def search_random_novela(self):
		screen_size = self.driver.get_window_size()
		width = screen_size['width']
		height = screen_size['height']
		swipe_start_x = width/2
		swipe_start_y = height*0.6
		swipe_end_x = width/2
		swipe_end_y = height*0.2
		while True:
			sleep(4)
			categories = self.driver.find_element_by_android_uiautomator('new UiSelector().description("Categorias")')
			categories.click()
			
			novelas = self.driver.find_element_by_android_uiautomator('new UiSelector().text("Novelas")')
			novelas.click()
			sleep(3)

			random.seed(time.time())
			n=0
			#Random number of swipes on novela screen
			while n<random.randint(0,6):
				self.driver.swipe(swipe_start_x,swipe_start_y,swipe_end_x,swipe_end_y,1000)
				n+=1
			random.seed(time.time())
			#Picks random novela from those currently on screen
			title_button = self.driver.find_elements_by_id("com.globo.globotv:id/view_holder_custom_view_grid_custom_view_title")[random.randint(0,5)]
			title_button.click()
			
			sleep(2)

			self.title_name = self.driver.find_element_by_id("com.globo.globotv:id/title").text
			self.title_name = self.title_name.lower()

			print self.title_name
			thumb_button = self.driver.find_element_by_id("com.globo.globotv:id/thumb")
			sleep(2)
			thumb_button.click()
			self.driver.implicitly_wait(2)
			try:
				self.driver.find_element_by_id("com.globo.globotv:id/activity_video_custom_view_download")
				break
			except:
				sleep(5)
				back_btn = self.driver.find_element_by_android_uiautomator('new UiSelector().description("Navigate up")')
		                back_btn.click()	
				sleep(3)
				back_btn = self.driver.find_element_by_android_uiautomator('new UiSelector().description("Navigate up")')
		                back_btn.click()
				continue

	def video_metrics_control(self):
		#Starting video and monitoring it's metrics
		self.status="Fail_video_Play"	
		video_start = int(round(time.time() * 1000))
		self.driver.implicitly_wait(1)
		t_end = time.time() +60
		while time.time() < t_end:
			try:
				spinner = self.driver.find_element_by_id('com.globo.globotv:id/progress_bar')
			except:
				print "Not displayed"
				break
			
		self.driver.implicitly_wait(1)
		t_end = time.time() +60
		while time.time() < t_end:
			try:
				spinner = self.driver.find_element_by_id('com.globo.globotv:id/progress_bar')
			except:
				video_end = int(round(time.time() * 1000))
				break
		self.video_load_time = video_end- video_start	
		self.driver.implicitly_wait(5)
	        try:
        	        self.driver.find_element_by_id("android:id/button1").click()
			sleep(2)
                	play_button.click()
                	video_second = int(round(time.time() * 1000))
                	self.driver.implicitly_wait(1)
                	t_end = time.time() +60
                	while time.time() < t_end:
                        	try:
                                	spinner = self.driver.find_element_by_id('com.globo.globotv:id/progress_bar')
                        	except:
                                	break

                	t_end= time.time() +60
                	while time.time() < t_end:
                        	try:
                                	spinner = self.driver.find_element_by_id('com.globo.globotv:id/progress_bar')
                        	except:
                                	video_play = int(round(time.time() * 1000))
                                	break
			self.video_load_time = video_play - video_second
 	        except: 
      			pass
	
		print "Video load time ", self.video_load_time
		d = {'globo_video_load_time': self.video_load_time}
		self.kpi_dic.update(d)
		sleep(4)	
		#Watch the Video for 1 minute	
		self.videoplay_check(30)
		self.driver.implicitly_wait(50)
	
	def test_login(self):
		self.driver.implicitly_wait(60)
		#Launching app
		agora_tab = self.driver.find_element_by_android_uiautomator('new UiSelector().description("Agora")')
		launched_app = int(round(time.time() * 1000))
		
		#calcualting launch time
		self.app_launch_time = launched_app - self.start_app
		print ("App Launch Time is %s ms" %self.app_launch_time)
		d = {'globo_launch_time': self.app_launch_time}
		self.kpi_dic.update(d)
		#incrementing pass count
		self.pass_count +=1
		sleep(2)

		self.delete_download()
		self.driver.implicitly_wait(60)
		
		home_tab = self.driver.find_element_by_id("com.globo.globotv:id/menu_bottom_navigation_view_item_home")
		home_tab.click()
		self.status="Fail_login"
		user_icon = self.driver.find_element_by_id("com.globo.globotv:id/menu_profile_custom_view_profile")
		user_icon.click()
		
		#Log out
		try:
			self.driver.implicitly_wait(5)
			logout =  self.driver.find_element_by_android_uiautomator('new UiSelector().text("Sair")')
			logout.click()
			#Confirm log out
			yes_btn = self.driver.find_element_by_id('android:id/button1')
			yes_btn.click()
			#Click on te account button
			self.driver.implicitly_wait(10)
			user_icon = self.driver.find_element_by_id("com.globo.globotv:id/menu_profile_custom_view_profile")
			user_icon.click()
		except:
			pass
		self.driver.implicitly_wait(60)
		entrar = self.driver.find_element_by_id('com.globo.globotv:id/activity_profile_text_view_get_int')
		entrar.click()
		self.driver.implicitly_wait(10)
		try:
			none_of_the_above = self.driver.find_element_by_id("com.google.android.gms:id/cancel")
			none_of_the_above.click()
		except:
			pass
		sleep(5)
		self.driver.implicitly_wait(60)
		email_id_tf = self.driver.find_element_by_class_name('android.widget.EditText')
		email_id_tf.set_value('laurent_headspin')
		#password
		password_tf = self.driver.find_elements_by_class_name('android.widget.EditText')[1]
		password_tf.set_value('Globo@321')
		
		sleep(5)
		buttons= self.driver.find_elements_by_class_name("android.widget.Button")
		for button in buttons:
			entrar = button.text
			if entrar =="ENTRAR":
				button.click()
				break
		
		self.status = "Fail_page_load_post_login"
		back_btn = self.driver.find_element_by_android_uiautomator('new UiSelector().description("Navigate up")')
		back_btn.click()
		home_page_load_start = int(round(time.time() * 1000))
		self.driver.implicitly_wait(0.5)
		t_end = time.time()+60
		while time.time() < t_end:
			try:
				self.driver.find_element_by_class_name('android.widget.ProgressBar')
			except:
				break
		
		self.driver.implicitly_wait(60)
		home_page = self.driver.find_element_by_id("com.globo.globotv:id/custom_view_premium_highlights_image_view_background")
		home_page_load_end = int(round(time.time() * 1000))
		self.home_pg_load_time = home_page_load_end- home_page_load_start
		d = {'globo_post_login_home_load_time': self.home_pg_load_time}
		self.kpi_dic.update(d)
		sleep(2)
		self.pass_count +=1
		print "Home page loading time ", self.home_pg_load_time	
		while True:
			self.search_random_novela()
			self.video_metrics_control()
			#*********Download content**********# 
			download_button = self.driver.find_element_by_id("com.globo.globotv:id/activity_video_custom_view_download")
			download_button.click()
			self.driver.implicitly_wait(15)
			try:
				start_download = int(round(time.time() * 1000))
				download_progress = self.driver.find_element_by_id("com.globo.globotv:id/custom_view_download_status_status_progress_bar")
				break
			except:
				download_limit = self.driver.find_element_by_class_name("android.widget.Button")
				download_limit.click()
				navigate_up = self.driver.find_element_by_android_uiautomator('new UiSelector().descriptionContains("Navigate up")')
				navigate_up.click()
				navigate_up = self.driver.find_element_by_android_uiautomator('new UiSelector().descriptionContains("Navigate up")')
				navigate_up.click()
				continue
		sleep(2)
		#video play pass count increment
		self.pass_count= self.pass_count+1
		self.driver.implicitly_wait(60)
		navigate_up = self.driver.find_element_by_android_uiautomator('new UiSelector().descriptionContains("Navigate up")')
		navigate_up.click()
		
		navigate_up = self.driver.find_element_by_android_uiautomator('new UiSelector().descriptionContains("Navigate up")')
		navigate_up.click()
		
		downloads_tab = self.driver.find_element_by_android_uiautomator('new UiSelector().descriptionContains("Downloads")')
		downloads_tab.click()
		sleep(2)
	
		download_title = self.driver.find_elements_by_id("com.globo.globotv:id/view_holder_download_text_view_title")
		
		screen_size = self.driver.get_window_size()
	        width = screen_size['width']
        	height = screen_size['height']

        	swipe_start_x = width/2
        	swipe_start_y = height*0.7
        	swipe_end_x = width/2
        	swipe_end_y = height*0.3
	
		self.driver.implicitly_wait(10)	
	
		for i in range(0,5):	
			try:
				options_menu = self.driver.find_element_by_id("com.globo.globotv:id/view_holder_download_title_text_view_downloading")
				break
			except:
				sleep(2)	
				self.driver.swipe(swipe_start_x,swipe_start_y,swipe_end_x,swipe_end_y)

		download_title = self.driver.find_elements_by_id("com.globo.globotv:id/view_holder_download_text_view_title")

		for title in download_title:
			download_title_name = title.text.lower()
			print download_title_name
			if download_title_name ==self.title_name:
				print "Title Added to list"
	                        self.title_check = True
        	                self.pass_count = self.pass_count+1
				break	
	
		options_menu = self.driver.find_element_by_id("com.globo.globotv:id/view_holder_download_title_text_view_downloading")
		options_menu.click()
			
		
		sleep(4)
		self.driver.implicitly_wait(5)
		
		#Waits for download to finish
		self.status="Fail_Download"
		t_end = time.time() + 1200
	        while time.time() < t_end:
			try:
				self.driver.find_element_by_id("com.globo.globotv:id/custom_view_download_status_status_progress_bar")
				continue
			except:
				self.driver.implicitly_wait(5)
				try:
					ok_entendi = self.driver.find_element_by_id("android:id/button1")
				except:
					self.driver.find_element_by_id("com.globo.globotv:id/custom_view_download_status_image_view_icon")	
				end_download = int(round(time.time() * 1000))
				self.download_time = end_download - start_download - 10000
				print "Download time:  ",self.download_time
				self.pass_count = self.pass_count+1
				d = {'globo_download_time': self.download_time}
				self.kpi_dic.update(d)
				break
		
		self.driver.implicitly_wait(50)
		self.delete_download()
		sleep(5)
		
		if self.title_check ==False:
			self.status="Fail_title_check"
		else:
			self.status = "Pass"