Software Testing Techniques LAB 02: Selenium
1. Installing
1. Install firefox 38.5.1
2. Install SeleniumIDE
After installing, I set the view of toolbox, then we can see this
3. Install Selenium Client & WebDrive
4. Install Selenium Standalone Server
5. Installed Test
After downloading we have these files
Then we test Selenium IDE on firefox firstly,
I recorded the script about signing in the Software Testing Techniques Website
Then I export the script,
Then I test the web driver,
First, I wrote the code about searching by Baidu.com
This is the result,
The installing is finished now!
2. Data processing
There is a big problem that the inputgit.csv file doesn’t use the Unicode to encoding.
So we can’t process it by JAVA.String function, and normally we open it with gibberish.
I have to change the encoding to UTF-8 WITH BOM
3. Coding and checking
1. Coding
The whole project looks like this
1.1 The csv files reader
readFile.java
Cut the last 6 num from student num as password
- pwd[idx] = num[idx].substring(4);
This is the whole code
- package Test1;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- public class readFile {
- public String[] num = new String[120];
- public String[] name = new String[120];
- public String[] add = new String[120];
- public String[] pwd = new String[120];
- public void read (){
- int idx = 0;
- File csv = new File("D:\\java\\workplace\\seleniumTest\\bin\\Test1\\inputgit.csv");
- BufferedReader br = null;
- try
- {
- br = new BufferedReader(new FileReader(csv));
- } catch (FileNotFoundException e)
- {
- e.printStackTrace();
- }
- String line = "";
- String[] everyLine = new String[3];
- try {
- line = br.readLine();
- while ((line = br.readLine()) != null)
- {
- everyLine =line.split(",");
- num[idx] = everyLine[0];
- name[idx] = everyLine[1];
- add[idx] = everyLine[2];
- pwd[idx] = num[idx].substring(4);
- idx++;
- }
- } catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- }
1.2 The NumTest.java
This file just come from the NumTest.java, but I add some functions and variables to store and return a Git address from test student number.
The most important part is set the web driver location
- System.setProperty("webdriver.firefox.bin", "D:\\oldfirefox\\firefox.exe");
- System.setProperty("webdriver.firefox.marionette", "D:\\oldfirefox\\geckodriver.exe");
Change function to receive the number and password from csv reader.
- public void testNum(String num, String pwd)
This is the whole code
- package Test1;
- import java.util.regex.Pattern;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- 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 NumTest {
- public String add;
- private WebDriver driver;
- private String baseUrl;
- private boolean acceptNextAlert = true;
- private StringBuffer verificationErrors = new StringBuffer();
- @Before
- public void setUp() throws Exception {
- System.setProperty("webdriver.firefox.bin", "D:\\oldfirefox\\firefox.exe");
- System.setProperty("webdriver.firefox.marionette", "D:\\oldfirefox\\geckodriver.exe");
- driver = new FirefoxDriver();
- baseUrl = "Invisible";
- driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
- }
- @Test
- public void testNum(String num, String pwd) throws Exception {
- driver.get(baseUrl + "/");
- driver.findElement(By.id("reset")).click();
- driver.findElement(By.id("name")).clear();
- driver.findElement(By.id("name")).sendKeys(num);
- driver.findElement(By.id("pwd")).clear();
- driver.findElement(By.id("pwd")).sendKeys(pwd);
- driver.findElement(By.id("submit")).click();
- add = driver.findElement(By.xpath("//tbody[@id='table-main']/tr[3]/td[2]")).getText();
- System.out.println(add);
- }
- @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;
- }
- }
- }
1.3 The mainCheck.java
This file contains the main function, and is control the whole program
- package Test1;
- public class mainCheck {
- public static void main(String args[]) {
- readFile readFile = new readFile();
- readFile.read();
- NumTest ntest = new NumTest();
- try {
- for (int idx = 0; idx < readFile.num.length;idx++ )
- {
- System.out.println(idx);
- ntest.setUp();
- ntest.testNum(readFile.num[idx], readFile.pwd[idx]);
- if (!ntest.add.equals(readFile.add[idx]) )
- System.out.println(readFile.num[idx]+"wrong!");
- else
- System.out.println(readFile.num[idx]+"right!");
- ntest.tearDown();
- }
- } catch (Exception e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- }
4. Result
I print all student number and if the github address is right then print “right!”
If wrong then print “wrong!”
But because this program is too slow to open firefox every time, so I didn’t run it for all student numbers
The more detail please come to my blog:
http://www.cnblogs.com/nocis/p/6618790.html
The code has been uploaded to my Github:
https://github.com/nocis/Software-Test/tree/master/seleniumTest
Software Testing Techniques LAB 02: Selenium的更多相关文章
- Software Testing Techniques LAB 01: test Junit and Eclemma
1. Installing 1. Install Junit and hamcrest First, I download the Junit-4.12.jar and hamcrest-core- ...
- Software Testing Techniques Homework 3
1. a.This is the chart b. initial numPrimes = 4, t1 would over the loop. c. t = ( n = 1) d. node cov ...
- Software Testing Techniques Homework 2
Problem 1 1. The fault is i > 0, it should be i >= 0, because if the case is x = [0], y= 0, w ...
- Software Testing Techniques Homework 1
I have met some errors in recent years, one of them which impress me most. It happend when I try to ...
- 读书笔记-Software Testing(By Ron Patton)
Software Testing Part I:The Big Picture 1.Software Testing Background Bug's formal definition 1.The ...
- Web Application Penetration Testing Local File Inclusion (LFI) Testing Techniques
Web Application Penetration Testing Local File Inclusion (LFI) Testing Techniques Jan 04, 2017, Vers ...
- 101+ Manual and Automation Software Testing Interview Questions and Answers
101+ Manual and Automation Software Testing Interview Questions and Answers http://www.softwaretesti ...
- Exploratory Software Testing
最近找到去年上半年看过一本关于测试方面书籍的总结笔记,一直放在我的个人U盘里,当时是用Xmind记录的,现在重新整理下分享给大家了! James A.Whittaker [美] 詹姆斯·惠特克(软件测 ...
- 软件测试software testing summarize
软件测试(英语:software testing),描述一种用来促进鉴定软件的正确性.完整性.安全性和质量的过程.软件测试的经典定义是:在规定的条件下对程序进行操作,以发现程序错误,衡量软件质量,并对 ...
随机推荐
- SpringMVC初写(二)映射类型、限制和数据绑定
映射路径 a)映射路径的概述 所谓的映射路径,就是匹配请求路径和执行方法关系的路径 请求路径:http://localhost:8080/springmvc-demo-cofig/say.do 映射路 ...
- (转载)Android xml资源文件中@、@android:type、@*、?、@+引用写法含义以及区别
原帖地址:http://blog.csdn.net/zfrong/article/details/7332545 Android xml资源文件中@.@android:type.@*.?.@+引用写法 ...
- 使用NHibernate(1)--资料汇总
NHibernate最新版本是4.0,目前还只是alpha版,没有发布.稳定版本是3.3,项目中用的也是这个版本,所以以后的介绍都是基于这个版本的. 在网上找了一下相关的学习资料,现汇总如下: NHi ...
- manjaro 添加tash 快捷方式
-In your home directory open /.local/share/applications/-Right click in this folder and create a emp ...
- Freemarker不显示对象的属性
Freemarker不显示对象的属性 今天使用Freemarker在springboot项目中通过模板生成一些html文件.但是发现没有显示对象的属性. 找了很长时间,终于发现不显示对象的属性可能是两 ...
- teleport助手不可以使用剪切板的问题解决
在使用teleport堡垒机的时候,你使用teleport助手会发现不可以使用剪切板,接下来就是解决方法. 解决办法:更新freerdp 基于环境:win10(win7下更新好像没有用),telepo ...
- 如何阅读复杂的C类型声明
阅读复杂的C类型声明,通常采用右左法则,也就是Clockwise/Spiral Rule (顺时针/螺旋法则). 本文将首先介绍工具(cdecl)(个人比较偏好使用工具提高学习和工作效率),然后中英文 ...
- spring之IOC模拟实现
使用Spring框架已经有很长时间了,一直没有仔细的想过框架的设计思想是什么样的,底层到底是怎么实现的,这几天调试程序看了些源码,写下来做个记录.由于Spring框架博大精深,个人理解的难免有不正确的 ...
- select2 下拉搜索 可编辑可搜索 / 只可搜索
官网 (http://select2.github.io/examples.html) <!--引入select2需要的文件--> <script type="text/j ...
- WPF实现动画的几种方式及其小案例
WPF实现动画的方式: 基于计时器的动画 建立一个定时器,然后根据其频率循环调用函数或者一个事件处理函数,在这个函数中可以手工更新目标属性,直到达到最终值,这时可以停止计时器. 案例: 效果图: XA ...