Selenium入门01

1、常用模块介绍

Selenium IDE 是一个FF插件,用于录制测试用例并重新运行。可以保持为html脚本,也可以导出为各种语言的单元测试
Selenium Html Runner 可以直接运行Selenium IDE导出的html脚本
Selenium Standalone Server 有三种运行模式(standalone、hub、node),后两种用于grid
Selenium Remote Control Selenium RC, Selenium1采用代理网站及JS注入的方式,达到操控网页的目的,在Selenium3已经取消支持
Browser Drivers Selenium2为在不修改网页的情况下,达到操控网页的无敌,利用了各种浏览器的API,达到操控浏览器的目的
Remote Web Drivers 远程运行测试(与Selenium Standalone Server或Selenium Standalone Hub进行交互时使用)
Selenium GRID 用于同时对多个操作系统的多种浏览器进行自动化测试(包括一个HUB,和多个NODE)
Language Binding 各种开发语言包

2、Selenium IDE
2.1、FF下载插件并重启
https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/
2.2、录制插件

用FF打开你要测试的网站
打开Selenium IDE
Tools->Selenium IDE
输入BaseURL,点击右侧小红点儿,开始录制
在页面上进行操作(最好不要切换页面)

2.3、保存TestSuit及TestCase

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
  <title>Test Suite</title>
</head>
<body>
<table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium"><tbody>
<tr><td><b>Test Suite</b></td></tr>
<tr><td><a href="neohope.case.search.html">neohope_search_testcase001</a></td></tr>
</tbody></table>
</body>
</html>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="https://www.neohope.com/" />
<title>neohope_search_testcase001</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">neohope_search_testcase001</td></tr>
</thead><tbody>
<tr>
	<td>open</td>
	<td>/</td>
	<td></td>
</tr>
<tr>
	<td>type</td>
	<td>name=s</td>
	<td>Metabase</td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>css=button.search-submit</td>
	<td></td>
</tr>
<tr>
	<td>assertXpathCount</td>
	<td>//article</td>
	<td>1</td>
</tr>

</tbody></table>
</body>
</html>

2.4、导出python脚本
Selenium IDE->File->Export Test Case As…->Python2/WebDriver

3、用selenium-html-runner运行
3.1、下载并配置jdk
3.2、下载selenium-html-runner-3.0.1.jar
3.3、在selenium网站下载对应浏览器的driver
http://www.seleniumhq.org/download/
3.4、运行

set JAVA_HOME=C:\NeoLanguages\Java\JDK\jdk_x86_1.8.0_77
set PATH=%JAVA_HOME%\bin;%PATH%;C:\NeoTest\TestSelenium\trunk\bin\x86\;
set webdriver.gecko.driver=C:\NeoTest\TestSelenium\trunk\bin\x86\geckodriver.exe

java -jar ../lib/selenium-html-runner-3.0.1.jar -htmlSuite *firefox "https://www.neohope.com/" "../testcases/neohope.suit" "../testcases/neohope.result"
PAUSE

Leave a Reply

Your email address will not be published. Required fields are marked *

*