在我们的应用中,我们使用的是视频发布API(https://static.opentok.com/v2/js/opentok.js)。
我的测试用例的问题是,我们在openttok.js中外部调用了一个方法“Connect( - , - )”。
但我们如何通过JMeter实现测试视频发布?
我尝试了以下方式,
Test Plan
Thread Group
Http Request
call cdn: https://static.opentok.com/v2/js/opentok.js
Post Request:
JSR223 PostProcessor: use variable in CDN JS
//OT varible is available in OpenTok JS.
var session = OT.initSession(apiKey, sessionID);
这些是屏幕:
但它会抛出错误
引起:jdk.nashorn.internal.runtime.ECMAException:ReferenceError:“OT”未定义
我认为,OpenTok没有加载或不可用于后处理器脚本。
如何加载OpenTok并在此Js中使用变量?
答案 0 :(得分:0)
You won't be able to do it this way as JMeter is not a browser and cannot execute JavaScript.
I would recommend the following approach
Obtain all the dependencies, for OpenTok Server 3.0.0 they would be
async-http-client-1.9.40.jar
commons-beanutils-1.9.2.jar
commons-digester-1.8.1.jar
commons-lang-2.6.jar
commons-logging-1.2.jar
commons-validator-1.6.jar
jackson-annotations-2.9.0.pr4.jar
jackson-core-2.9.0.pr4.jar
jackson-databind-2.9.0.pr4.jar
jose4j-0.5.1.jar
netty-3.10.6.Final.jar
Use the following code to create a session:
import com.opentok.OpenTok
def apiKey = 123456789
def apiSecret = 'your_api_secret'
OpenTok opentok = new OpenTok(apiKey,apiSecret)
def session = opentok.createSession()
References: