HTML5语言实现的视频播放器

2018-08-01  本文已影响0人  测试媛617

思路:调用javascript的获取文件存储地址方法、获取播放时长,开始播放,暂停等方法。

# encoding = utf-8
import unittest
from selenium import webdriver
import time

class TestDemo(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()


    def test_HTML5videoPlayer(self):
        url = "http://www.w3school.com.cn/tiy/loadtext.asp?f=html5_video_simple"
        self.driver.get(url)
        # print(self.driver.page_source)
        videoPlayer = self.driver.find_element_by_tag_name("video")
        # 获取视频文件网络存储地址
        videoSrc = self.driver.execute_script("return arguments[0].curentSrc;",videoPlayer)
        print(videoSrc)
        # 断言视频存放地址是否符合预期
        # self.assertEqual(videoSrc,"http://www.w3school.com.cn/i/movie.ogg")
        # 获取文件播放时长
        videoDuration = self.driver.execute_script("return arguments[0].duration;",videoPlayer)
        print(videoDuration)
        self.assertEqual(int(videoDuration),3)
        # 播放影片
        self.driver.execute_script("return arguments[0].play();",videoPlayer)
        time.sleep(2)
        # 暂停3秒
        self.driver.execute_script("return arguments[0].pause();",videoPlayer)
        time.sleep(3)
        self.driver.save_screenshot("test.png")

    def tearDown(self):
        self.driver.quit()


if __name__ == '__main__':
    unittest.main()


上一篇下一篇

猜你喜欢

热点阅读