• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

sebarmeli/Selenium2-Java-QuickStart-Archetype: Maven Archetype for getting start ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

sebarmeli/Selenium2-Java-QuickStart-Archetype

开源软件地址(OpenSource Url):

https://github.com/sebarmeli/Selenium2-Java-QuickStart-Archetype

开源编程语言(OpenSource Language):

Java 100.0%

开源软件介绍(OpenSource Introduction):

Introduction

This archetype generates a small Maven project with Selenium 2 and TestNG embedded to make it easy to get started testing with Selenium Web Driver.

This project provides just a starting point to get up to speed with Selenium 2 infrastructure.

To install the archetype in your local repo:

git clone https://github.com/sebarmeli/Selenium2-Java-QuickStart-Archetype.git
cd Selenium2-Java-QuickStart-Archetype
mvn install

Now, you can use the archetype in a new project typing:

mvn archetype:generate -DarchetypeGroupId=com.sebarmeli -DarchetypeArtifactId=selenium2-java-quickstart-archetype -DarchetypeVersion=0.3 -DgroupId=<mygroupId> -DartifactId=<myartifactId>

where mygroupId : group id of the project you are creating; myartifactId : artifact id of the project you are creating

It uses Java bindings for Selenium version 2.47.2 and TestNG version 6.9.6. OperaDriver 1.5, Appium's ios-driver 3.2.0 and Selendroid 0.16.0 are also included for convenience.

Project Structure

The project follows the standard Maven structure, so all the tests go in the src/test/java folder. Tests should inherit from the TestBase class. In this class a factory method from WebDriverFactory class is in charge of generating the instance of the WebDriver interface you need. Different parameters are passed into the factory:

  • base URL : base URL of the AUT (application under test)
  • Grid 2 hub URL : URL of the hub (if using Grid 2)
  • browser fatures: a) name b) version c) platform
  • username / password : in case of BASIC authenticated site

Those parameters are retrieved from the src/main/resources/application.properties file. You can also populate the properties file from command line (through -D<property in mvn command or through Hudson/Jenkins).

TestBase class provides 30 seconds as interval for polling element from the DOM (implicity wait), and also it takes care of closing the driver when all the tests are executed in the suite. (Feel free to update all this values according to your needs)

HomePageTest class (in src/test/java/pages) is just an example of a test class for testing the homepage of a web application. This test class accepts the path parameter (set in src/test/resources/testng.xml) defining the path appended to the base URL (in case of the home page, usually just "/"). In the setup method of this class, the PageFactory class is used to help supporting the PageObject pattern (see below for more information). Briefly according to this pattern, each page is an object. src/main/java/pages/HomePage class is an example of a class representing the home page. Notice how the constructor accepts the "WebDriver" interface as parameter and all the "services" available for that page should be exposed here. It also allows to decouple the DOM element from the functionalities offered by the page.

In the TestBase class, I commented out the method launched after the suite runs and it takes screenshots in case of failure. Feel free to uncomment it out if you need and if your driver supports that funcitonality. (at the moment it's not supported on mobile devices)

Adding Chrome Driver to the project

If you need to use chromedriver, you should put the proper driver file downloaded from http://code.google.com/p/chromium/downloads/list into src/main/resources/drivers/chrome. If you are on Windows, the file should be named chromedriver.exe, if on Unix-based system, the file should be named chromedriver.

TestNG

For more info around TestNG framework, go to http://testng.org/doc/index.html. If you prefer, you could substitute this framework with JUnit.

Page Object pattern

For more info around this pattern, read this wiki page: https://github.com/SeleniumHQ/selenium/wiki/PageObjects

Integration with SauceLabs

You can easily integrate the project with SauceLabs, great service to launch tests in the cloud. You need to retrieve your SauceLab key and setting the "grid2.hub" property with thid syntax: http://:@ondemand.saucelabs.com:80/wd/hub

Further Notes

The project is just a starting point, feel free to modify it according to your needs.

Credits

The selenium2-java-quickstart-archetype project is an open source project licensed under the Apache License 2.0.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap