Some of you may already know Selenium. Basically it’s free and open source tool for web application functional testing. It’s mainly know as replacement for HP’s QuickTestProfessional. I’ve recently discovered Selenium as very helpful for automating data setup for load testing.
Here is a small description howto setup Eclipse and run Selenium script through it.
1) Download Eclipse IDE from http://www.eclipse.org/downloads/
2) Download Selenium RC from http://seleniumhq.org/download/
3) Download Junit from http://www.junit.org/
4) Create new project in Eclipse:
- Go to File -> New -> Java Project
- enter project name e.g. “Sample”
- Click “Finish” button
5) Import Selenium and JUnit packages into the project:
- In Package Explorer right click project “Sample” and select Properties
- Go to “Java Build Path” then select “Libraries” tab
- Click “Add External JARs” and import junit-4.7.jar and selenium-java-client-driver.jar
Now our Eclipse environment should be ready. Next step is to prepare a test case in Selenium IDE. I’ve prepared small test that searches for “linux” word in google. To export test case as Java, in Selenium IDE go to Options -> Format -> Java (Junit) Selenium RC. As a result you should get something like this:
package com.example.tests;
import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
public class Untitled extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://change-this-to-the-site-you-are-testing/", "*chrome");
}
public void testUntitled() throws Exception {
selenium.open("/");
selenium.type("q", "linux");
selenium.click("btnG");
}
}
Default Junit code generated by Selenium doesn’t use Selenium RC. Because of that I updated the code a little bit to connect to localhost Selenium RC on port 4444. Here is updated version:
package com.example.tests;
import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
public class Untitled extends SeleneseTestCase {
public DefaultSelenium selenium;
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com/");
selenium.start();
}
public void testUntitled() throws Exception {
selenium.open("/");
selenium.type("q", "linux");
selenium.click("btnG");
}
}
Now, lets add it in our Eclipse project:
- In Package Explorer right click on our “Sample” project and select New -> Class
- Enter class name “Untitled” and package name “com.example.tests”
- Click “Finish” button
Before we run our test, we need to start Selenium RC. For that open command line and under selenium-remote-control-1.0.1/selenium-server-1.0.1 run command “java -jar selenium-server.jar”. It will run Selenium RC server on default port 4444.
Now, to start the test just select Run -> Run As -> Junit test. It should open two IE browsers. One for Selenium RC and second with Google results for “linux” word.
Because we run Java code, it’s only up to us how we want to run the test. Below is our example update to search for “linux” word in a loop 5 times with 5 seconds intervals.
package com.example.tests;
import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
public class Untitled extends SeleneseTestCase {
public DefaultSelenium selenium;
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com/");
selenium.start();
}
public void testUntitled() throws Exception {
for(int i = 0; i < 5; i++)
{
selenium.open("/");
selenium.type("q", "linux");
selenium.click("btnG");
selenium.waitForPageToLoad("10000");
Thread.sleep(5000);
}
}
}
分享到:
相关推荐
It is widely used around the world as a tool for automating test for web application. In this book we use Selenium WebDriver to perform automatic operation of the browser. As for browser we use both ...
Introducing Microsoft Flow Automating Workflows Between Apps and Services 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
Automating Microsoft Azure with Powershell 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
It is widely used around the world as a tool for automating test for web application. In this book we use Selenium WebDriver to perform automatic operation of the browser. As for browser we use both ...
Learn to use PhantomJS and CasperJS to automate your interaction with the web to perform numerous tasks such as data scraping, network monitoring, page rendering, and browser testing in a programmatic...
西门子 plc Hans Berger Automating with 系列丛书 Automating with SIMATICS 7-1500 Configuring, Programming and Testingwith STEP 7 Professional 2017.pdf
With this book, you will learn how to deal with many tasks such as zipping files, emailing colleagues, and deploying your work at the press of a button. The book is structured into two parts: The ...
Primarily it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) also be automated as well. ...
It is widely used around the world as a tool for automating test for web application. In this book we use Selenium WebDriver to perform automatic operation of the browser. As for browser we use both ...
It is widely used around the world as a tool for automating test for web application. In this book we use Selenium WebDriver to perform automatic operation of the browser. As for browser we use both ...
《使用PLC自动化制造系统V7.0 2010年版》一书深入探讨了可编程逻辑控制器(PLC)在制造业自动化中的应用,为读者提供了从基础理论到实际操作的全面指导。以下是对该书中关键知识点的详细解析。 ...
Techniques for automating continuous integration with AntHill and Cruise Control How to harness plugins for JUnit, Cactus, and Ant in the Eclipse IDE Ways to implement Extreme Programming best ...
Techniques for automating continuous integration with AntHill and Cruise Control How to harness plugins for JUnit, Cactus, and Ant in the Eclipse IDE Ways to implement Extreme Programming best ...
Techniques for automating continuous integration with AntHill and Cruise Control How to harness plugins for JUnit, Cactus, and Ant in the Eclipse IDE Ways to implement Extreme Programming best ...
Techniques for automating continuous integration with AntHill and Cruise Control How to harness plugins for JUnit, Cactus, and Ant in the Eclipse IDE Ways to implement Extreme Programming best ...