实习生真的可以在任何Selenium服务上运行吗?

时间:2015-10-30 15:36:52

标签: javascript testing automated-tests intern

我已经为the Intern编写了一些功能测试,据说它应该适用于SauceLabs,BrowserStack,TestingBot,我自己的Selenium网格。

但是,相同的代码似乎并不适用于所有服务。我最初在SauceLabs上进行了功能测试,因此我可以将该服务用作我的" base",可以这么说。

在BrowserStack上,测试似乎失败了,因为命令执行得太快了。例如,我正在使用.pressKeys('TEST\nIN\nPROGRESS\n'),其中\n应该在页面上执行javascript以将之前的文本转换为标记(例如此问题的SO标记:[intern] [javascript] [testing])。

该命令应该产生以下结果:

[TEST] [IN] [PROGRESS]

但改为

[TESTIN] [PROGRESS]

导致我的断言失败。将pressKeys命令更改为

.pressKeys('TEST\n')
.sleep(500)
.pressKeys('IN\n')
.sleep(500)
.pressKeys('PROGRESS\n')

没有解决问题。测试将通过/失败不一致,标签有时[TEST] [IN] [PROGRESS]形式出现,有时标记为[TESTIN] [PROGRESS]

另一个例子是,当我在链接上.click()时,它总是等待下一页加载,即使之后有.sleep()命令。

关于TestingBot,应用程序违规无法上传文件,我终生无法弄清楚如何启用这样做所需的file_watcher服务。他们有file upload example here,但我不知道如何配置实习生为我做这件事。

实习生是否应该在云提供商处理这些差异以进行测试?

是否有一些标准化的方式在实习生中编写我的测试,以便我可以在不更改测试的情况下更改我的云测试提供程序?

1 个答案:

答案 0 :(得分:1)

It should be possible to run the same test suite against any cloud-hosted Selenium providers and have them execute successfully, but there are some things you must do:

  1. You need to make sure you’ve correctly configured providers so they all run the same version of Selenium. There is no standard for this; each provider uses a different key to decide which Selenium version to run. Check each provider’s documentation for the correct key to use.

  2. You need to write tests that don’t have race conditions. What you’re describing here sounds like a classic race condition where you are performing some action that completes asynchronously, and so only happens in environments that execute operations within a certain period of time. Modifying this specific test so it has a find timeout and then tries to find the element you expect to be generated when the return key is hit should be a good solution, since this will allow you to wait as long as necessary without making your test slow.

Unfortunately, even with this advice, all of the cloud-hosted providers for Web browser testing are garbage and mess with things in a way that randomly causes tests to break. BrowserStack is the best by far at avoiding this, but even they do things to break tests from time to time that work perfectly well in a locally hosted Selenium installation.

For file uploads, Intern will automatically upload files if has detected that the remote provider supports it, and you type a valid path to a file on the server where intern-runner is running. You can check whether the server supports uploads by looking at this.remote.session.capabilities.remoteFiles. Feature detection must be turned on for this to work, and you should run Intern 3.0.6 or newer if you are trying to upload files to a Selenium server on the same machine as intern-runner.