我可以使用selenium-webdriver一次(同时)运行多个实例吗? [英] Can I run multiple instances at once(simultaneously) with selenium-webdriver?

查看:1757
本文介绍了我可以使用selenium-webdriver一次(同时)运行多个实例吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Selenium自动执行文件上传.

I'm trying to use Selenium to automate file uploading.

我已经用 selenium-webdriver 编写了一个小程序可行.

I'v already wrote a tiny program with the selenium-webdriver that works.

问题是,有数千个文件需要上传,我想同时运行多个浏览器实例以加快自动化速度.所以我尝试了这样的事情

The problem is, there are thousands of files need to be uploaded, I'd like to run multiple browser instances simultaneously to speed up the automation. So I tried something like this

var i = 0;
while (i < 10) {
    i++;
    var driver = new webdriver.Builder()
            .forBrowser('firefox')
            .build();

    // login and upload files......
}

我希望这将一次创建10个浏览器实例,并同时进行自动化.

I expected this would create 10 browser instances at once, and do the automation simultaneously.

但是实际上...上面的代码将创建浏览器实例一个一个",这意味着,直到上一个实例完成,它才会创建另一个实例.

But actually... the above code will creates browser instance 'one by one' which means, it won't create another instance until the previous one finishes.

我还尝试在多个shell实例中执行该程序,这将为我启动多个浏览器实例,但我只是不想这样做...

I'v also tried execute the program in multiple shell instances, that will fire up multiple browser instances for me, but I just don't want to do this...

推荐答案

好,您需要创建多个线程而不是循环,然后才能在并行线程中启动每个上载.您走在正确的轨道上.您不需要硒网格即可实现这一目标.

Well you need to create multiple threads instead of looping, then you can start each upload in parallel threads. You are on the right track. You dont need selenium grid to achieve this.

有关多线程的查找.您可以从 answer

lookup about multithreading. You can start with this answer

执行多个浏览器会话需要网格是不对的.您可以通过创建多个驱动程序对象并对其进行管理来调用多个浏览器会话.如果您希望每个会话都是独立的.

It's not right you need grid for executing multiple browser sessions. You can invoke multiple browser sessions by just creating multiple driver objects, and managing them. Each session will be separate if you want them to be.

网格用于扩展,因为可以运行的浏览器实例数量不受限制,可以保持机器性能不变并测试稳定.就像在一台机器上超过5个chrome实例一样.如果您想做更多的事情,那么您必须使用Selenium Grid.

Grid is for scaling as there is a limitation on the no of browser instances you can run keeping your machine performance intact and tests stable. Like more than 5 chrome instances in a single machine. If you want to do more than that then you have to use selenium Grid.

这篇关于我可以使用selenium-webdriver一次(同时)运行多个实例吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆