在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):sebarmeli/Selenium2-Java-QuickStart-Archetype开源软件地址(OpenSource Url):https://github.com/sebarmeli/Selenium2-Java-QuickStart-Archetype开源编程语言(OpenSource Language):Java 100.0%开源软件介绍(OpenSource Introduction):IntroductionThis 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:
Now, you can use the archetype in a new project typing:
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 StructureThe 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:
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 projectIf 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. TestNGFor 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 patternFor more info around this pattern, read this wiki page: https://github.com/SeleniumHQ/selenium/wiki/PageObjects Integration with SauceLabsYou 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 NotesThe project is just a starting point, feel free to modify it according to your needs. CreditsThe selenium2-java-quickstart-archetype project is an open source project licensed under the Apache License 2.0. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论