Selenium ide及webDriver使用
2012-12-19 11:52
387 查看
官方网站:http://seleniumhq.org/
Selenium-IDE于firefox上脚本测试。并可以通过该插件生成对应JavawebDriver适用的Junit测试代码。 下面是根据Firefox上录制产生的Junit代码,部分找HTML的ELEMENT时候代码需要自己手动更改。
ViewCode
packagecom.example.tests; importjava.util.concurrent.TimeUnit; importorg.junit.*; importstaticorg.junit.Assert.*; importorg.openqa.selenium.*; importorg.openqa.selenium.firefox.FirefoxDriver; importorg.openqa.selenium.support.ui.Select; publicclassTestDemo{ privateWebDriverdriver; privateStringbaseUrl; privateStringBufferverificationErrors=newStringBuffer(); @Before publicvoidsetUp()throwsException{ //driver=newHtmlUnitDriver(); driver=newFirefoxDriver(); baseUrl="http://localhost:8080/"; driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); } @Test publicvoidtest()throwsException{ driver.get(baseUrl+"/pcloud-web/serve/login.do"); driver.findElement(By.id("userId")).clear(); driver.findElement(By.id("userId")).sendKeys("hello@163.com"); driver.findElement(By.id("fullName")).clear(); driver.findElement(By.id("fullName")).sendKeys("hello@163.com"); driver.findElement(By.id("mobile")).clear(); driver.findElement(By.id("mobile")).sendKeys("13932132121"); driver.findElement(By.id("submit")).click(); driver.findElement(By.id("phone")).clear(); driver.findElement(By.id("phone")).sendKeys("13932132121"); driver.findElement(By.id("phone-check")).click(); driver.findElement(By.id("phone-check")).clear(); driver.findElement(By.id("phone-check")).sendKeys("13932132121"); newSelect(driver.findElement(By.id("face-select"))).selectByVisibleText("10元"); Thread.sleep(1000); //开始直接购买 driver.findElement(By.id("direct-charge")).click(); Thread.sleep(5000); for(Stringhandle:driver.getWindowHandles()){ driver.switchTo().window(handle); } driver.findElement(By.xpath("(//a[contains(text(),'我的订单')])[2]")).click(); Thread.sleep(1000); try{ assertTrue(driver.findElement(By.cssSelector("td[class='status']")).getText().equals("成功")); }catch(Errore){ verificationErrors.append(e.toString()); } } @After publicvoidtearDown()throwsException{ driver.quit(); StringverificationErrorString=verificationErrors.toString(); if(!"".equals(verificationErrorString)){ fail(verificationErrorString); } } privatebooleanisElementPresent(Byby){ try{ driver.findElement(by); returntrue; }catch(NoSuchElementExceptione){ returnfalse; } } }
相关文章推荐
- Selenium WebDriver使用Junit创建数据驱动测试
- 在Selenium Webdriver中使用XPath Contains、Sibling函数定位
- Selenium webdriver 使用python脚本处理SWFupload 文件上传
- Selenium ide导出 webdriver 脚本运行浏览器启动与selenium包兼容性
- 总结Selenium WebDriver中一些鼠标和键盘事件的使用
- 在Selenium WebDriver中使用By.Xpath快速定位页面元素
- Selenium Webdriver 的使用java执行js代码 解决 ScriptEngine不支持浏览器内置对象window,document的问题
- selenium webdriver使用的一些小技巧(持续更新中)
- Selenium 2.0 WebDriver 自动化测试 使用教程 实例教程 API快速参考
- Selenium WebDriver使用经验杂记
- selenium+python的WebDriverWait使用方法
- 转:Selenium Webdriver使用技巧(一)
- Selenium2(webdriver)入门之TestNG的安装与简单使用
- 使用selenium webdriver进行元素定位
- Selenium web driver 使用JS修改input属性
- selenium2 webdriver 简单使用
- selenium webdriver使用
- 使用Selenium-webdriver对页面进行截图操作
- Selenium 2.0 WebDriver 自动化测试 使用教程 实例教程 API快速参考
- 【selenium webdriver】selenium.JavascriptExecutor.executeScript() 使用实例