使用Selenium Server测试无线路由器Web管理页面

发表于:2013-5-23 10:18

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:kenneth    来源:51Testing软件测试网采编

  最近在做WIFI吞吐率的测试,需要登录到无线路由器的Web管理页面对无线参数的频段和模式等进行更改。更改无线参数之后,再使用IxChariot等工具对WIFI吞吐率进行测试。项目组想把这个过程自动化起来,IxChariot工具自动化很容易实现,对无线参数的更改决定使用Selenium工具进行自动化更改。遇到的问题是,访问http://192.168.1.1时,无法解决登录问题,因为Selenium不支持Windows安全对话框(windows security dialog)!对话框上面的信息为:位于Mercury Wireless Router MW548R的服务器192.168.1.1 要求用户名和密码。警告:此服务器要求以不安全的方式发送您的用户名和密码(没有安全连接的基本认证)。

  来自www.openqa.org的解决方式为:

  How do I use Selenium to login to sites that require HTTP basic authentication (where the browser makes a modal dialog asking for credentials)?

  Use a username and password in the URL, as described in RFC 1738:

  Test Type

  open http://myusername:myuserpassword@myexample.com/blah/blah/blah

  Note that on Internet Explorer this won’t work, since Microsoft has disabled usernames/passwords in URLs in IE. However, you can add that functionality back in by modifying your registry, as described in the linked KB article. Set an “iexplore.exe” DWORD to 0 in HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE.

  If you don’t want to modify the registry yourself, you can always just use Selenium Remote Control, which automatically sets that that registry key for you as of version 0.9.2.

  中文解释如下:

  可以把用户名和密码加到URL中进行解决,比如http://admin:admin@192.168.1.1这样就不会再需要登录,直接进去操作即可。对于IE,需要修改注册表,把下属内容复制到reg格式的文件双击执行即可。

  Windows Registry Editor Version 5.00

  [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE]

  “iexplore.exe”=dword:00000000

  下面给出相关的Selenium的源代码:

package dw.junit;
import org.junit.*;
import com.thoughtworks.selenium.*;
 
public class MercuryTesting extends SeleneseTestBase {
 private static Selenium selenium;
 
 @BeforeClass
 public static void setUpBeforeClass() throws Exception {
  selenium = new DefaultSelenium("localhost", 4444, "*iexplore",
    http://192.168.1.1);
  System.out.println("正在启动Selenium。。。");
  selenium.start();
  selenium.setTimeout(60 * 1000 + "");
  selenium.windowMaximize();
  selenium.open(http://admin:admin@192.168.1.1/);
 }
 
 @AfterClass
 public static void tearDownAfterClass() throws Exception {
  if (selenium != null) {
   System.out.println("停止Selenium!");
   selenium.stop();
  }
 }
 
 @Test
 public void testaa() {
  // 点击左侧的无线参数导航链接
  selenium.click("//a[text()='无线参数']");
  // 切换模式
  selenium.select("//select[@name='mode']", "label=11Mbps (802.11b)");
 }
}

  本文转载自:http://loggingselenium.com/?p=335

100家互联网大公司java笔试题汇总,填问卷领取~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号