Selenium Examples


Selenium Examples

Today, one of my friends wanted to query his GCT(Graduate Candidate Test) scores,
and he knew his ID number, but he forgot his Admission Form No., it is easy to find out the first 11 digits assigned to his school,
but he just knew the range of last four digits, so he asked me to help to figure it out.

The first thought is to write a program and use HttpURLConnection to submit form and analyze response,
but it failed for some reason, and don't want the friend to wait for a long time, so I gave up my
first idea, and resort to Selenium.

1: start selenium server:
Download Selenium RC.
cd selenium-remote-control-1.0.1-dist\selenium-server-1.0.1
java -jar selenium-server.jar (to run the server in interactive mode execute java -jar selenium-server.jar -interactive)

2: Then write the following code:
import com.thoughtworks.selenium.SeleneseTestCase;
public class Scores extends SeleneseTestCase {
    public void setUp() throws Exception {
        setUp("http://**.edu.cn/", "*");
    }

    public void testScores() throws Exception {
        String idNo = "*******************";
        String admFormNoPrefix = "************";
        int admFormNoUnknownPartStart = 1000, admFormNoUnknownPartEnd = 3000;
        boolean notMatch = true;
        selenium.setTimeout("300000");
        for (int i = admFormNoUnknownPartStart; i < admFormNoUnknownPartEnd; i++) {
            selenium.open("/graduate/**.htm");
            selenium.type("zjhm", idNo);
            selenium.type("ksbh", admFormNoPrefix + i);
            selenium.click("B1");
            selenium.waitForPageToLoad("10000");
            notMatch = selenium.isTextPresent("Id No. and Admission Form No. don't match.");
            if (!notMatch) {
                System.out.println("Admission Form No.= " + admFormNoPrefix + i);
            }
            assertTrue(notMatch);
        }
    }
}
Then Run it as JUnit Test.
At last, problem resolved, and thanks, Selenium :)

Resources:
http://blog.taragana.com/index.php/archive/5-minute-guide-to-selenium-ide-and-selenium-rc-test-tools/
http://blog.taragana.com/index.php/archive/9-important-tips-for-selenium-remote-control-java-client-test-tool/

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)