您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源功能測(cè)試工具 > Selenium
使用Selenium Server測(cè)試無線路由器Web管理頁面
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2014/3/21 9:50:29 ] 推薦標(biāo)簽:Selenium 無線路由器 Web管理頁面

  近在做WIFI吞吐率的測(cè)試,需要登錄到無線路由器的Web管理頁面對(duì)無線參數(shù)的頻段和模式等進(jìn)行更改。更改無線參數(shù)之后,再使用IxChariot等工具對(duì)WIFI吞吐率進(jìn)行測(cè)試。項(xiàng)目組想把這個(gè)過程自動(dòng)化起來,IxChariot工具自動(dòng)化很容易實(shí)現(xiàn),對(duì)無線參數(shù)的更改決定使用Selenium工具進(jìn)行自動(dòng)化更改。遇到的問題是,訪問http://192.168.1.1時(shí),無法解決登錄問題,因?yàn)镾elenium不支持Windows安全對(duì)話框(windows security dialog)!對(duì)話框上面的信息為:位于Mercury Wireless Router MW548R的服務(wù)器192.168.1.1 要求用戶名和密碼。警告:此服務(wù)器要求以不安全的方式發(fā)送您的用戶名和密碼(沒有安全連接的基本認(rèn)證)。

  來自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_USERSoftwareMicrosoftInternet ExplorerMainFeatureControlFEATURE_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中進(jìn)行解決,比如http://admin:admin@192.168.1.1這樣不會(huì)再需要登錄,直接進(jìn)去操作即可。對(duì)于IE,需要修改注冊(cè)表,把下屬內(nèi)容復(fù)制到reg格式的文件雙擊執(zhí)行即可。

  Windows Registry Editor Version 5.00

  [HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMainFeatureControlFEATURE_HTTP_USERNAME_PASSWORD_DISABLE]

  “iexplore.exe”=dword:00000000

  下面給出相關(guān)的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("正在啟動(dòng)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() {
  // 點(diǎn)擊左側(cè)的無線參數(shù)導(dǎo)航鏈接
  selenium.click("//a[text()='無線參數(shù)']");
  // 切換模式
  selenium.select("//select[@name='mode']", "label=11Mbps (802.11b)");
 }
}

軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd