【发布时间】:2019-02-01 16:21:51
【问题描述】:
我在 Windows 7 中使用 Selenium 3 webdriver 和 Python 3。
我想录制一段关于我的硒测试中发生的事情的视频。
为此,我使用FFmpeg 和screen-capture-recorder,但我可以更改程序。
这是我的代码:
import unittest
from selenium import webdriver
from subprocess import Popen
#from subprocess import call
cmd = 'ffmpeg -y -rtbufsize 2000M -f dshow -i video="screen-capture-recorder" -r 10 -t 20 screen-capture.mp4'
class SearchProductTest(unittest.TestCase):
def setUp(self):
# start the recording of movie
self.videoRecording = Popen(cmd)
# create a new Firefox session
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.driver.maximize_window()
# navigate to the application home page
self.driver.get("http://demo-store.seleniumacademy.com/")
def test_search_by_category(self):
# get the search textbox
search_field = self.driver.find_element_by_name("q")
search_field.clear()
# enter search keyword and submit
search_field.send_keys("phones")
search_field.submit()
# get all the anchor elements which have product names displayed
# currently on result page using find_elements_by_xpath method
products = self.driver.find_elements_by_xpath(
"//h2[@class='product-name']/a")
# check count of products shown in results
self.assertEqual(3, len(products))
#self.videoRecording.terminate()
def test_something_else(self):
pass
def tearDown(self):
# close the browser window
self.driver.quit()
# Stop the recording
self.videoRecording.terminate()
#def terminate(process):
#if process.poll() is None:
# call('taskkill /F /T /PID ' + str(process.pid))
if __name__ == '__main__':
unittest.main(verbosity=2)
问题是:
1) cmd 给出每部电影的最大时间(示例中为 20")。如果测试持续时间更长,则创建电影并且它可以工作(但不完整,只有 20")。
2) 如果测试持续时间较短,则创建文件但它不起作用(阅读器无法读取它,它只是一些字节)。这是主要错误!我不确定从哪里开始播放电影以及在哪里(以及如何)停止。
3) 如果我有多个测试,我希望所有测试都只有一部电影(所以我想在同一部电影中记录所有测试)。
4) 如果可能的话,我更愿意记录 webdriver 窗口(我的测试正在运行的那个)而不是我的屏幕,所以在测试进行的同时我可以做其他事情(它们很慢)。
感谢您的帮助。
【问题讨论】:
标签: python selenium selenium-webdriver ffmpeg video-capture