WebRTC 快速测试
Table of Contents
搭建测试环境
启动测试程序
git clone git@github.com:walterfan/webrtc_video_chat.git
cd webrtc_video_chat
./start.sh
启动浏览器
cd /Applications/Google\ Chrome\ Canary.app/Contents/MacOS/
./Google\ Chrome\ Canary --disable-webrtc-encryption
Chrome 有些 WebRTC 相关的测试开关很有用
-
--allow-file-access-from-files
allows getUserMedia() to be called from file:// URLs. -
--disable-gesture-requirement-for-media-playback
removes the need to tap a<video>
element to start it playing on Android. -
--use-fake-ui-for-media-stream
avoids the need to grant camera/microphone permissions. -
--use-fake-device-for-media-stream
feeds a test pattern to getUserMedia() instead of live camera input. -
--use-file-for-fake-video-capture=path/to/file.y4m
feeds a Y4M test file to getUserMedia() instead of live camera input.
使用 Selenium Webdriver 的基本步骤如下
- Basic Steps in a Selenium WebDriver Script
- Create a WebDriver instance.
- Navigate to a webpage.
- Locate a web element on the webpage via locators in selenium.
- Perform one or more user actions on the element.
- Preload the expected output/browser response to the action.
- Run test.
- Record results and compare results from them to the expected output.
#!/usr/bin/env python3
import random
import pytest
import os
import sys
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions as EC
import json
import logging
import signal
import uuid
class TestClient:
def __init__(self, name, node_url):
self._name = name
self._node_url = node_url
self._config = {
"ice_server_url": "stun:www.fanyamin.com:3478"
}
self._driver = self.create_driver(self._node_url)
self._driver.maximize_window()
self._driver.implicitly_wait(20)
def create_driver(self, node_url):
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--ignore-ssl-errors=yes')
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--allow-file-access-from-files')
chrome_options.add_argument('--enable-local-file-accesses')
chrome_options.add_argument('--enable-media-stream')
chrome_options.add_argument('--disable-webrtc-encryption')
chrome_options.add_argument('--no-default-browser-check')
chrome_options.add_argument('--use-fake-ui-for-media-stream')
chrome_options.add_argument('--use-fake-device-for-media-stream')
driver = webdriver.Remote(
command_executor=node_url,
options=chrome_options
)
return driver
def join(self, room_id, site_url, room_url):
self._driver.get(site_url)
self._config["room_url"] = room_url
room_id_txt = self._driver.find_element(By.ID, "roomId")
room_id_txt.clear()
room_id_txt.send_keys(room_id)
config_txt = self._driver.find_element(By.ID, "cfgMessage")
config_txt.clear()
config_txt.send_keys(json.dumps(self._config, indent = 4))
join_btn = self._driver.find_element_by_id("joinRoom")
join_btn.click()
start_btn = self._driver.find_element_by_id("startMedia")
start_btn.click()
call_btn = self._driver.find_element_by_id("call")
call_btn.click()
def leave(self):
self._driver.quit()
class TestCall:
def setup(self):
self.clients = {}
self.clients["Alice"] = TestClient('Alice', 'http://10.224.85.4:4444/wd/hub')
self.clients["Bob"] = TestClient('Bob', 'http://10.224.85.242:4444/wd/hub')
def test_call(self):
site_url = 'https://10.224.85.4:8043'
room_url = "wss://10.224.85.4:8003"
room_id = str(uuid.uuid4())
self.clients["Alice"].join(room_id, site_url, room_url)
self.clients["Bob"].join(room_id, site_url, room_url)
for name, client in self.clients.items():
print("{} join room {}/{} on {}".format(name, room_id, room_url, site_url))
client.join(room_id, site_url, room_url)
sleep(900)
def teardown(self):
for name, client in self.clients.items():
print("{} leave room".format(name))
client.leave()
if __name__ == '__main__':
pytest.main(['-s', '-q', '--html=./report.html'])
Comments |0|
Category: Uncategorized