尝试在JMeter中的CDN js中加载CDN和调用方法

时间:2017-07-12 07:30:30

标签: jmeter

在我们的应用中,我们使用的是视频发布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);

这些是屏幕:

OpenTok.js的Http请求 enter image description here

后处理器: enter image description here

但它会抛出错误

  

引起:jdk.nashorn.internal.runtime.ECMAException:ReferenceError:“OT”未定义

我认为,OpenTok没有加载或不可用于后处理器脚本。

如何加载OpenTok并在此Js中使用变量?

1 个答案:

答案 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

  1. Download Opentok Server jar
  2. 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
    
  3. Put all the .jars under JMeter Classpath
  4. Restart JMeter to pick the jars pu
  5. Add JSR223 Sampler to your Test Plan
  6. 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: