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