1.自己电脑上有Firefox,最好路径是默认安装的。
2.去selenium 官网下载http://docs.seleniumhq.org/download/
选择自己想要的IDE,一般都是最新的,点Download latest released version后面的版本号就可以了。
允许,然后安装所有的插件。
安装完之后在Firefox->>工具 最下方有一个Selenium IDE 这说明selenium已经成功安装。
3.一般我们用selenium不仅仅是录制用到IDE,还会用到RC来查看代码,我自己用的是java,所以下载了java的selenium-server-standalone-2.37.0.jar,然后在eclipse上选好的文件下右键,选Build Path>>Add External Archives把selenium-server-standalone-2.37.0.jar文件选中上传。
4.当我们点开selenium IDE的窗口的时候我们会看看到有录制的按钮,要注意的是如果你想查看录制后的java
代码,选在selenium IDE->>Options下面给选项“Enable experimental features”前面打勾。
5.打开selenium IDE(默认录制按钮在打开的时候已经是开始的),访问一个www.baidu.com,点击音乐,输入test进行搜索,然后点击完成按钮,完成录制,这个时候我们会到看到一个Command等相关的图,
这个时候我们再去选Options->>Format->>Java/Junit4/WebDriver,确定以后会看到刚刚录制过成生成的对应java代码。
package com.example.tests;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class Untitled {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://www.baidu.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testUntitled() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.linkText("音乐")).click();
driver.findElement(By.id("ww")).sendKeys("test");
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
相关推荐
python+selenium+eclipse环境搭建
python+selenium+unittest环境搭建1
搭建Selenium+Eclipse+Python环境
终极自动化测试环境搭建:Selenium+Eclipse+Junit+TestNG+Python
Selenium+Eclipse+Junit+TestNG,Selenium自动化测试框架以及使用步骤_详细备注
终极自动化测试环境搭建:Selenium+Eclipse+Junit+TestNG+Python
Selenium终极自动化测试环境搭建(一):Selenium+Eclipse+Junit+TestNG.docx
selenium+python+pycharm环境搭建文档selenium+python+pycharm环境搭建文档selenium+python+pycharm环境搭建文档
1、Testng+selenium+Maven+WebDriver+Java+eclipse 实现禅道登录,百度搜索。 2、eclipse需安装Testng+selenium+Maven 3、下载对应版本的WebDriver驱动。Chrome驱动下载地址...
Selenium终极自动化测试环境搭建(二):Selenium+Eclipse+Python .docx
Selenium+Eclipse+Junit+TestNG自动化学习笔记
从下载安装python到pycharm如何连接svn,一整个流程都有介绍和截图
selenium+eclipse开发过程中需要的所有jar包,包括一个43.3版本的firefox
selenium3+python3环境搭建,绕开小坑,轻松实现自动化。
Instalation_Tutorial_Selenium+Python+Eclipse.pdfInstalation_Tutorial_Selenium+Python+Eclipse.pdf
selenium+firefox+eclipse+pydev安装
主要介绍了Java+Eclipse+Selenium环境搭建的方法步骤,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧