码迷,mamicode.com
首页 > 其他好文 > 详细

Selenium上机实验

时间:2017-03-26 21:20:36      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:seconds   dism   mat   title   after   try   man   regex   ica   

 实验步骤:

1、安装SeleniumIDE插件

2、学会使用SeleniumIDE录制脚本和导出脚本

3、访问http://121.193.130.195:8080/使用学号登录系统(账户名为学号,密码为学号后6位),进入系统后可以看到该同学的git地址。

4、编写Selenium Java WebDriver程序,测试inputgit.csv表格中的学号和git地址的对应关系是否正确。

 

5、将测试代码提交到github

实验操作步骤:

1、下载Firefox24.0,安装并在工具栏中点击工具找到添加附件,点击,在右下角点击添加更多附件,在右上角搜索

SeleniumIDE

技术分享

点击黄色按钮,自动下载,完成安装。

2、点击菜单栏中的工具,点击SeleniumIDE,如下

技术分享

进行录制脚本和导出脚本:

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 Test {
  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://start.firefoxchina.cn/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void test() throws Exception {
    driver.get(baseUrl + "/");
    driver.findElement(By.id("search-key")).clear();
    driver.findElement(By.id("search-key")).sendKeys("王者荣耀");
    driver.findElement(By.id("search-submit")).click();
    driver.findElement(By.xpath("//div[@id=‘1‘]/h3/a/em[2]")).click();
    driver.findElement(By.cssSelector("#VideoTypeId_751_index > li")).click();
    driver.findElement(By.cssSelector("a[title=\"官网首页\"]")).click();
    driver.findElement(By.cssSelector("#VideoTypeId_751_index > li")).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;
    }
  }
}

  3、访问http://121.193.130.195:8080/使用学号登录系统(账户名为学号,密码为学号后6位),进入系统后可以看到该同学的git地址。

技术分享

 

技术分享

4、编写Selenium Java WebDriver程序,测试inputgit.csv表格中的学号和git地址的对应关系是否正确:

主要代码:

技术分享

 

结果:

技术分享

5、将测试代码提交到github上:

https://github.com/luhe1378228170/hello/blob/master/lab2

 

Selenium上机实验

标签:seconds   dism   mat   title   after   try   man   regex   ica   

原文地址:http://www.cnblogs.com/luhe-1378228170/p/6623967.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!