qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          使用Selenium Server測試無線路由器Web管理頁面

           最近在做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("http://a[text()='無線參數']");
            // 切換模式
            selenium.select("http://select[@name='mode']", "label=11Mbps (802.11b)");
           }
          }

            本文轉載自:http://loggingselenium.com/?p=335

          posted on 2013-05-24 11:42 順其自然EVO 閱讀(423) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2013年5月>
          2829301234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 竹溪县| 金川县| 郑州市| 苏尼特右旗| 清涧县| 工布江达县| 依安县| 英山县| 星座| 汉中市| 萨迦县| 青铜峡市| 南昌市| 乡宁县| 千阳县| 临高县| 林口县| 闻喜县| 大埔区| 神农架林区| 夏邑县| 松阳县| 平乡县| 洪雅县| 绥芬河市| 桑日县| 吴桥县| 宣威市| 承德县| 米易县| 天峻县| 塘沽区| 乌兰浩特市| 象州县| 定兴县| 长武县| 金沙县| 通江县| 岳阳市| 会泽县| 海南省|