Can I run HTML based Selenium tests when I'm offline?

橙三吉。 提交于 2019-12-08 06:52:54

问题


I'm a newbie with Selenium and am using the Selenium IDE, so I'm ending up with table structures like this:

<table cellspacing="1" cellpadding="1" border="1" name="SELENIUM-TEST">
  <thead>
    <tr class="title">
      <td colspan="3">UI Basic Interaction</td>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>store</td>
      <td><urltool portal_url="" at=""></urltool></td>
      <td>base_url</td>
    </tr>
    ...
    <tr>
     <td>waitForPageToLoad</td>
     <td><br></td>
     <td></td>
    </tr>
    <tr>
     <td>waitForElementPresent</td>
     <td>//div[@id="global-panel"]</td>
     <td></td>
    </tr>
   </tbody>
 </table>

I'm required to run this test offline, that means I should not simulate the browser being offline, but really "unplug" and then run the tests.

Question:
I'm not really finding a lot of information on Selenium and offline usage, so is this at all possible when using the Selenium IDE? Thanks for some pointers!


回答1:


You can unplug and take your machine offline by disabling the LAN connection before running the selenium tests, and then re-enabling it after.

On Windows 7/Vista and above, you can use the below commands wmic commands (requires cmd.exe is Run as Administrator).

First, get a list of all NICs on the machine, and their index:

 wmic nic get name, index

To Disable NIC, run the command:

 wmic path win32_networkadapter where index=7 call disable

To Enable NIC, run the command:

 wmic path win32_networkadapter where index=7 call enable

7 in the above examples is the index of the NIC adapter to disable, which can be found by looking at Network properties for the LAN connection.

I believe the index number does not change (unless you install/uninstall NICs), so you should be good enough obtaining the index once and then building .bat files for the enable disable commands.

These commands are not available on Windows XP, where you can use the devcon.exe tool (from Microsoft) instead (see it's command line help for usage).




回答2:


Selenium does nothing more than interact with the browser. It does this by starting a driver (remotewebdriver, chromedriver, firefoxdriver, etc) which kicks off a browser instance. That instance allows WebDriver to hook into the dom and control it like a user does. It does not give you OS control therefore file downloads can be difficult. There are plenty of instructions on how to do that though. Assuming your page is local and all links are as well, you shouldn't have any problem. If you want to use the remote web driver, you'll need to setup a grid on that pc. Otherwise, simply use one of the local drivers.

  • Selenium Hub/Node as Windows Service


来源:https://stackoverflow.com/questions/22230100/can-i-run-html-based-selenium-tests-when-im-offline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!