Application of Testng+selnium+eclipse test framework

Source: Internet
Author: User
Tags testng

One: testng installation in eclipse
(1) Click Help->install New Software in eclipse


(2) Click "Add" button, enter the corresponding address

(3) Shanga the testng option, click "Install"
This completes the installation of the testng in eclipse

II: TESTNG Configuration in Eclipse
(1) Create a new project, select the project name right click, choose Build path-> "Add Libraties", add testng


(2) Create a new testng Class and configure the Testng.xml file

Three: Add and run Selenium
(1) Add selenium corresponding jar package (previous article already introduced)
(2) Add selenium running code to TESTNG class
Like what:

Package Testng_findelement;import Java.util.iterator;import Java.util.list;import java.util.set;import Javax.swing.text.abstractdocument.content;import Org.junit.assert;import Org.openqa.selenium.by;import Org.openqa.selenium.keys;import Org.openqa.selenium.webdriver;import Org.openqa.selenium.webelement;import Org.openqa.selenium.firefox.*;import Org.openqa.selenium.interactions.actions;import Org.testng.annotations.aftertest;import Org.testng.annotations.beforetest;import org.testng.annotations.Test; Import Testhelloworld.constant;import Testhelloworld.driverutils;public class Testng_exp {webdriver driver;@ beforetestpublic void Pre () {System.setproperty ("Webdriver.firefox.bin", "E:/program Files/mozilla firefox/ Firefox.exe ");d river = new Firefoxdriver (); @Testpublic void Basic_by () {driver.get ("https://www.jd.com");d river.manage (). window (). Maximize ();/by ClassName usage Webelement text = driver.findelement (By.classname ("text")); Text.sendkeys ("Dress"); Actions builder = new actions (driver); bUilder.sendkeys (Keys.enter). Perform ();//The usage of the by ID driver.findelement (by.id ("Ttbar-myjd")). Click (); Webdriver window = Driverutils.getwantdriver (driver,constant.jd_login_title);//By name use webelement LoginName = Window.findelement (By.name ("LoginName")); Loginname.sendkeys (Constant.name); Webelement nloginpwd = window.findelement (By.name ("nloginpwd")); Nloginpwd.sendkeys (CONSTANT.PWD); Window.findelement (By.id ("Loginsubmit")). Click (); @AfterTestpublic void later () {Driver.close ();}}

(3) Let the program Fly (run Testng.xml)

Application of Testng+selnium+eclipse test framework

Related Article

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.