Automated Test Learning (eight) Selenium 2.0 environment based on MAVEN

Source: Internet
Author: User
Tags xmlns seleniumhq

Before I said a kind of square test to build selenium RC environment, that article is based on the Selenium RC 1.0 way, the current official website has not provided 1.0 download, I provide the download link is csdn on.

In fact, if you are familiar with MAVEN, selenium RC will become easy and easy, of course, my operation is based on the Java language camp.

Prerequisite: You need to have a MAVEN environment. For a MAVEN environment, please refer to this blog's article on maven. The left navigation bar has a set of MAVEN environment related articles.

First step:

CMD opens the command prompt symbol and creates a MAVEN project with the following commands:

MVN archetype:generate-dgroupid=mysel20proj-dartifactid=mysel20proj-dversion=1.0

Open the project you created, locate the Pom.xml file under the project directory, and open it before <dependencies>...</dependencies> add the following:

<dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId> selenium-java</artifactid>
       <version>2.16.1</version>
 </dependency>

We changed the JUnit version to 4.2. The complete Pom.xml code after the modification is as follows:

<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < Modelversion>4.0.0</modelversion> <groupId>MySel20Proj</groupId> <artifactid& Gt
        
      Mysel20proj</artifactid> <version>1.0</version> <packaging>jar</packaging> <name>MySel20Proj</name> <url>http://maven.apache.org</url> <pro Perties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> &LT;/PROPERTIES&G
        
      T <dependencies> <dependency> <groupId>junit</groupId> <artifactid&gt ;junit</artifactid> <version>4.2</version> <scope>test</scope> &
Lt;/dependency>    
        <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifa
      Ctid>selenium-java</artifactid> <version>2.16.1</version> </dependency> </dependencies> </project>

Ok.! Now switch to the project directory under the command prompt symbol:

D:java\mysel20proj> MVN Eclipse:clean

D:java\mysel20proj> MVN Eclipse:celipse Perform this need to download the corresponding package, time will be a bit longer.

Now import our built projects into eclipse and refer to my MAVEN article if you have any questions.

Http://www.cnblogs.com/fnng/archive/2011/12/02/2272610.html

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/project/

We still use the previous code to test, (this code is based on the Selenium 1.0 selenium RC)

Import com.thoughtworks.selenium.*;
Import Org.junit.After;
Import Org.junit.Before;
Import Org.junit.Test;
Import Java.util.regex.Pattern;
    
public class Test extends Selenesetestcase {
    @Before public
    void SetUp () throws Exception {
        selenium = new Def Aultselenium ("localhost", 4444, "*iexplore",
                "http://www.baidu.com/");
                Selenium.start ();
    }
    
    @Test public
    void Testtest () throws Exception {
        Selenium.open ("/");
        Selenium.type ("id=kw", "AAAA");
        Selenium.click ("Id=su"); 
            }
    
    @After public
    void Teardown () throws Exception {
        selenium.stop ();
    }
 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.