Cainiao automated testing (8) -- selenium 2.0 Environment Building (based on maven)

Source: Internet
Author: User
Tags seleniumhq selenium grid

 

I have talked about how to build a solution.Selenium RCWhichArticleIs based onSelenium RC 1.0.Currently, the official website does not provide1.0The download link I provided isCsdn.

In fact, if you are familiarMavenThen,Selenium RCIt will become easy and easy. Of course, my operations are based onJavaLanguage camp.

Premise: You must haveMavenEnvironment. AboutMavenFor more information about how to build an environment, seeMaven. There areMavenRelated Articles on Environment setup.

 

Step 1:

CMDOpen the command prompt symbol to createMavenProject, the command is as follows:

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

 

Open the created Project and findPom. xmlFile, open, in <dependencies>... </Dependencies>Add the following content before:

 

 <  Dependency  > 
< Groupid > Org. seleniumhq. Selenium</ Groupid >
< Artifactid > Selenium-Java </ Artifactid >
< Version > 2017.1 </ Version >
</ Dependency >

 

We willJUnitVersion changed4.2. The modifiedPom. xmlCodeAs 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 > Mysel20proj </ Artifactid >
< Version > 1.0 </ Version >
< Packaging > Jar </ Packaging >

< Name > Mysel20proj </ Name >
< URL > Http://maven.apache.org</ URL >

< Properties >
< Project. Build. sourceencoding > UTF-8 </ Project. Build. sourceencoding >
</ Properties >

< Dependencies >
< Dependency >
< Groupid > JUnit </ Groupid >
< Artifactid > JUnit</ Artifactid >
< Version > 4.2 </ Version >
< Scope > Test </ Scope >
</ Dependency >
 
< Dependency >
< Groupid > Org. seleniumhq. Selenium </ Groupid >
< Artifactid > Selenium-Java </ Artifactid >
< Version > 2017.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: celipseTo execute this operation, you need to download the corresponding package for a long time.

 

Now import the project we have builtEclipseIf you have any questions, please refer to myMavenArticle.

 

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

 

We still use the previous code for testing ,(This code is based onSelenium 1, 1.0OfSelenium 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 Defaultselenium ("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 ();
}
}

 

Of course, you can use the selenium ide recording script to export the script to a Java language for testing. For more information, see:
Http://www.cnblogs.com/fnng/archive/2011/10/19/2217506.html

-- The above Code and method are no longer recommended. Because selenium 2.0 came, the stage of selenium RC was about to exit.

 

 

Add a plug-in using Maven


To get an overview of different selenium Maven artifacts, please see that it shows the selenium Maven artifacts and the most important classes and the dependencies between these class interfaces:

 

If you want to use different webdrivers to run code, such as firefoxdriver, you do not have to rely on selenium Java to build it (many of them transmit dependencies), you only needPom. xmlAdd the corresponding plug-in to the file.

 

<  Dependency  > 
< Groupid > Org. seleniumhq. Selenium </ Groupid >
< Artifactid > Selenium-Firefox-driver </ Artifactid >
< Version > 2.18.0 </ Version >
</ Dependency >

 

Then, in cmd (command prompt), rebuild the project (execute the MVN Eclipse: Eclipse command again ). Maven automatically downloads the required firefoxdriver jar package.

 

 

 

If you are using defaultselenium (or remotewebdriver implementation), you still need to start selenium server. The best way is to download selenium server standalone. jar, just use it. In addition, you can embed the dependency in the selenium server of your project. If you add the dependency to your pom. xml file:

 

 <  Dependency  > 
< Groupid > Org. seleniumhq. Selenium </ Groupid >
< Artifactid > Selenium-Server </ Artifactid >
< Version > 2.18.0 </ Version >
</ Dependency >

Note: This selenium server product depends on the servlet-API-2.5 product. If your project runs on a Web applicationProgramContainer dependencies, which should be excluded.

 

 

 

Third-party browsers are not supported. Please useSeleniumhqDeveloped plug-ins;

 

 <  Dependency  > 
< Groupid > Com. Opera </ Groupid >
< Artifactid > Operadriver </ Artifactid >
< Version > 0.10 </ Version >
</ Dependency >


 

The above references:

 

Http://seleniumhq.org/docs/03_webdriver.html

Http://seleniumhq.org/download/maven.html


 

What isSelenium 1, 2.0?

 

 

 

At a higher level, selenium consists of three tools. The first tool, selenium IDE, is an extension of Firefox that supports user recording and return test. Recording/Return Visit mode? The second tool, selenium Webdriver, is not suitable for many users. Therefore, selenium WebDriver provides APIs in various language Environments to support more control and write applications that comply with standard software development practices. The last tool, selenium grid, helps engineers use the selenium API to control browser instances distributed on a series of machines and supports concurrent running of more tests. Within the project, they are called "ide", "WebDriver", and "Grid" respectively ".

 

What we can see now:Selenium2.0 = selenium1.0 + WebDriver

 

What isWebDriver?

 

Webdriver is a tool for automated testing of Web applications, especially to verify that they operate as expected. It is designed to provide a friendly API that is easier to explore and understand than selenium-RC (1.0) API, this will help make your test easier to read and maintain. It does not rely on any specific test framework, so it can be used in a unit test, or from a common old "Main" method.

Next, let's take a look at how selenium 2.0 is new.WebDriver!

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.