selenium自动化测试脚本.docx_第1页
selenium自动化测试脚本.docx_第2页
selenium自动化测试脚本.docx_第3页
selenium自动化测试脚本.docx_第4页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

package .selenium;import java.util.concurrent.TimeUnit;import org.junit.*;import static org.junit.Assert.*;import org.openqa.selenium.*;import org.openqa.selenium.chrome.ChromeDriver;public class First private WebDriver driver; private String baseUrl; private boolean acceptNextAlert = true; private StringBuffer verificationErrors = new StringBuffer(); Before public void setUp() throws Exception System.setProperty(webdriver.chrome.driver,D:/chromedriver_win32/chromedriver.exe); driver = new ChromeDriver(); baseUrl = /; driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); Test public void testFirst() throws Exception driver.get(baseUrl + /); driver.findElement(By.id(kw).click(); driver.findElement(By.id(kw).clear(); driver.findElement(By.id(kw).sendKeys(天气预报); driver.findElement(By.id(su).click(); driver.findElement(By.xpath(/tableid=1/tbody/tr/td/h3/a/em2).click(); 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; # -*- coding: UTF-8 -*-from selenium import webdriverfrom mon.by import Byfrom mon.keys import Keysfrom selenium.webdriver.support.ui import Selectfrom mon.exceptions import NoSuchElementExceptionimport unittest, time, reimport osclass Pythontest(unittest.TestCase): def setUp(self): chromedriver = D:chromedriver_win32chromedriver.exe os.environwebdriver.chrome.driver = chromedriver self.driver = webdriver.Chrome(chromedriver) self.driver.implicitly_wait(30)#智能等待30秒 self.base_url = self.verificationErrors = self.accept_next_alert = True def test_python(self): driver = self.driver driver.get(self.base_url + /)# driver.find_element_by_name(wd).click()# print(1)# driver.find_element_by_name(wd).clear()# print(2) driver.find_element_by_name(wd).send_keys(uselenuim) print(3) driver.find_element_by_id(su).click() print(4) driver.find_element_by_link_text(朋友网).click() def is_element_present(self, how, what): try: self.driver.find_element(by=how, value=what) except NoSuchElementException, e: return False return True def is_alert_present(self): try: self.driver.switch_to_alert() except NoAlertPresentException, e: return False return True def close_alert_and_get_its_text(self): try: alert = self.driver.switch_to_alert() alert_text = alert.text if self.accept_next_alert: alert.accept() else: alert.dismiss() return alert_text finally: self.accept_next_alert = True def tearDown(self): self.driver.quit() self.assertEqual(, self.verificationErrors)if _name_ = _main_: unittest.main()package .selenium;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.support.ui.ExpectedCondition;import org.openqa.selenium.support.ui.WebDriverWait;public class Selenium2Example public static void main(String args) /创建一个WebDriver实例 System.setProperty(webdriver.chrome.driver,D:/chromedriver_win32/chromedriver.exe); WebDriver driver= new ChromeDriver(); / 访问google driver.get(); / 另一种访问方法 / driver.navigate().to(); / 找到文本框 WebElement element= driver.findElement(B(wd); / 输入搜索关键字 element.sendKeys(Selenium); /提交表单 WebDriver会自动从表单中查找提交按钮并提交 element.submit(); / 检查页面title System.out.println(Page title is: + driver.getTitle(); / google查询结果是通过javascript动态呈现的. / 设置页面等待10秒超时 (new WebDriverWait(driver, 10).un

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论