Webdriver(Selenium2)-如何使硒操作元素而又不浪费时间连接到外部AD链接? [英] Webdriver(Selenium2) - How to make selenium operate elements without wating for connecting to external AD links?

查看:89
本文介绍了Webdriver(Selenium2)-如何使硒操作元素而又不浪费时间连接到外部AD链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:
-Selenium 2.39独立服务器
-PHP 5.4.11
-PHPUnit 3.7.28
-Chrome V31& ChromeDriver v2.7

Environment:
- Selenium 2.39 Standalone Server
- PHP 5.4.11
- PHPUnit 3.7.28
- Chrome V31 & ChromeDriver v2.7

我正在测试一个网站,该网站会调用很多广告系统,例如Google AD.
浏览器需要花费很多时间才能连接到外部AD链接,甚至页面的所有元素都已加载.

I'm testing a website,which invokes a lot of Advertisement Systems,such as Google AD.
The browser takes a lot of time to connect to external AD links , even all the elements of the page has already been loaded.

如果在网页上运行测试时我的互联网连接不畅, 由于AD链接响应缓慢,Selenium将等待很长时间.
在这种情况下,硒通常要等待60秒以上,并抛出超时异常.

If my internet network was not fast when I ran my tests on a webpage, Selenium would wait for a very long time ,since the AD links responsed slowly.
Under this condition ,Selenium usually waits for over 60 seconds, and throws a timeout exception.

我不确定Senelium的工作方式,但Selenium似乎必须等待网页完全加载的迹象,然后再拉DOM来查找元素.

I'm not sure how Senelium works, but it seems that Selenium has to wait for a sign of webpage's full loading, then pulls the DOM to find elements.

我想让硒操作元素而不必等待与外部AD链接的连接.
有没有办法做到这一点 ?非常感谢.

I want to make selenium operate elements without waiting for connectiong to external AD links.
Is there a way to do that ? Thank you very much.

推荐答案

我终于找到了一种适合我情况的简单解决方案.

I finally found a simple solution for my condition.

我决定阻止这些广告请求,并尝试了一些防火墙和代理软件,例如, comodo,私有防火墙等 comodo太重且太复杂,privatefirewall不支持通配符,防火墙会中断测试.
最后,我选择了一个代理软件 CCproxy .试用版就足够了. 我为localhost创建一条规则,以使其只能请求我的测试网站域,而所有其他请求均被拒绝.

I decide to block these Ad requests and tried some firewall and proxy softwares,for example, comodo,privatefirewall, etc. comodo is too heavy and complex ,privatefirewall doesn't support wildcards, and firewall would interrupt tests.
At last I choosed a proxy software CCproxy. Trial Version is enough. I create a rule for localhost ,to make it can request my test website domain only, and all other requests are rejected.

运行测试大约要花费1-2分钟的时间,而之前仅需30秒,显然,它无需连接到无用的广告链接即可更加稳定,快速地运行.

Running a test costs about 1-2 minutes before and only 30 seconds now ,it's apparently more stable and fast without connecting to the useless Ad links.

以下是配置步骤:
1.以管理员"特权启动CCproxy(您应该使用管理员"在文件属性中进行设置)
2.单击选项",选择自动启动",然后为本地IP地址"选择自动检测".单击确定.
3.创建一个txt文件,输入您的域,例如"* .rong360.com *; *.rong360.*;"
4.单击帐户",为许可证类别"选择"PermitOnly";
单击新建",为"IP地址/范围"输入127.0.0.1;
选择WebFilter,单击右侧的E按钮以创建过滤器;
单击...按钮,选择您在Step3中创建的文本文件,
选择PermittedSites.单击确定
单击确定.
5.单击确定"返回到CCproxy的主UI.
6.启动IE并使用127.0.0.1:808
配置本地代理 其他浏览器也会自动使用此配置.

Here're configuration steps:
1.launch CCproxy with Administor privilege( you should set it using Adminisrator in the file property)
2.click Options, select AutoStartup,select AutoDetected for Local IP Address. click OK.
3.create a txt file ,input your domains,like " *.rong360.com*;*.rong360.*; "
4.click Account, select PermitOnly for Permit Category;
click New, input 127.0.0.1 for IP Address/Range;
select WebFilter,click the E button at right side to create a filter;
click the ... button,select the text file you create at Step3,
select PermittedSites. click OK
click OK.
5.click OK to return to the main UI of CCproxy.
6.launch IE and config the local proxy with 127.0.0.1:808
other browsers will use this config automatically too.

现在您可以再次运行测试,如果条件相同,您会感觉更好:)

now you can run the tests again , you'll feel better if have same condition :)

这篇关于Webdriver(Selenium2)-如何使硒操作元素而又不浪费时间连接到外部AD链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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