小编Mar*_*ner的帖子

混合客户端/服务器端测试

我应该如何构建包含Selenium代码(用于设置页面)和客户端Mocha代码(用于在被测试的客户端JS上实际执行测试)的测试?

我正在测试客户端javascript库.单元测试与Karma,Mocha和Grunt配合使用.单元测试可以在本地运行,也可以通过SauceLabs运行.单元测试基本上可以测试文件实际提交的部分.这部分需要浏览器自动化和/或手动交互,这正是我所挣扎的.

有问题的库是一个Javascript文件上传库.它具有分块,自动恢复等功能.它不需要jQuery,它适用于各种浏览器(IE7-10,FF,Safari(Mac和iOS),Chrome,Android股票浏览器).因此,这些测试中涉及很多案例和例外.

基本上,我需要使用Selenium来设置页面.由于我正在测试客户端JS文件上传库,我需要使用Selenium以编程方式提交文件,以便实际上传.一旦该文件已提交(从当您尝试上载一个或多个文件在网上出现的对话框窗口中选择一个文件的等价物),然后客户端测试可以运行,以确保UI已经正确绘制,文件中有被发现等

我试图围绕如何正确地测试它,以及如何设置我的测试套件以便将来可扩展,强大,简单/易于使用.

  • 我是否应该使用Selenium注入JS代码以运行客户端?

    一个想法是在Selenium的适当时机注入客户端JS代码.这是我正在思考的一些伪代码:

describe("A Test", function () {

   it("injects some JS", function (done) {
        // Assume `getClientSideScript` loads some .js file from the filesystem,
        // reads its contents, and returns the contents as a string (to be executed).
        browser.safeExecute(getClientSideScript('initialize'), function (err, result) {
            // At this point, the client-side library is initialized on the page.

            // Assume that `uploadFile` will submit a file to the `<input type='file'>`
            // element
            utils.uploadFile('file.jpg', function (file) {

                browser.safeExecute(getClientSideScript('test_file_submission'), …
Run Code Online (Sandbox Code Playgroud)

javascript selenium mocha.js saucelabs

7
推荐指数
1
解决办法
1123
查看次数

标签 统计

javascript ×1

mocha.js ×1

saucelabs ×1

selenium ×1