使用Selenium网络驱动器上运行多个浏览器测试 [英] Using selenium web driver to run test on multiple browsers
问题描述
我试图通过循环运行在多个浏览器中相同的测试,但它永远只能在Firefox上运行。
I'm trying to run a same test across multiple browsers through for loop but it always run only on Firefox.
bros = ['FIREFOX','CHROME','INTERNET EXPLORER']
for bro in bros:
print "Running "+bro+"\n"
browser = webdriver.Remote(
command_executor='http://10.236.194.218:4444/wd/hub',
desired_capabilities={'browserName': bro,
'javascriptEnabled': True})
browser.implicitly_wait(60000)
browser.get("http://10.236.194.156")
一个有趣的现象;当我包括参数平台:WINDOWS
它在Internet Explorer只能在运行
One interesting observation; when I include the parameter platform: WINDOWS
it's running only on Internet Explorer.
请问硒的webdriver这种方式工作或我的理解是错误的?
Does Selenium Webdriver works this way or my understanding is wrong?
推荐答案
其实我已经在Java中做到了这一点,下面的工作很适合我:
I actually have done this in java, the following works well for me:
...
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
...
DesiredCapabilities[] browsers = {DesiredCapabilities.firefox(),DesiredCapabilities.chrome(),DesiredCapabilities.internetExplorer()};
for(DesiredCapabilities browser : browsers)
{
try{
System.out.println("Testing in Browser: "+browser.getBrowserName());
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), browser);
...
您需要,如果你在一个不同的语言编写测试,以适应这当然,我知道这是可能在Java中,不知道其他。
You will need to adapt this of course if you're writing your tests in a different language, I know it's possible in Java, not sure about otherwise.
另外,我同意你想要做什么,我认为这是要好得多有运行不同的浏览器相同的测试类,而不是重复以上code多次被不雅。如果你在的Java /其他codeS这样做,我也强烈建议使用页面对象
Also, I agree with what you're trying to do, I think it is much better to have a class that runs the same tests with different browsers, instead of duplicating code many times over and being inelegant. If you are doing this in Java/other codes, I also highly suggest using a Page Object.
祝你好运!
这篇关于使用Selenium网络驱动器上运行多个浏览器测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!