• testng+selnium+eclipse的测试框架运用


    一:TestNG在Eclipse中的安装
    (1)点击eclipse中的Help->Install New Software
    截图323

    (2)点击【Add】按钮,输入相应的地址
    截图324
    (3)勾选加载出来的TestNG选项,点击【Install】
    这样就完成了testng在eclipse的安装

    二:TestNG在Eclipse中的配置
    (1)新建一个项目,选择项目名称点击右键,选择Build Path->【Add Libraties】,添加TestNG
    截图325

    截图326
    (2)新建一个TestNg Class,并且配置testng.xml文件
    截图327

    截图328

    三:添加并运行selenium
    (1)添加selenium相应的jar包(前面文章已经介绍)
    (2)把selenium运行的代码添加到TestNG Class中
    比如:

    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;
    
    	@BeforeTest
    	public void pre() {
    		System.setProperty("webdriver.firefox.bin",
    				"E:/Program Files/Mozilla Firefox/firefox.exe");
    		driver = new FirefoxDriver();
    	}
    
    	@Test
    	public void Basic_by() {
    		driver.get("https://www.jd.com");
    		driver.manage().window().maximize();
    
    		// by classname的用法
    		WebElement text = driver.findElement(By.className("text"));
    		text.sendKeys("连衣裙");
    		Actions builder = new Actions(driver);
    		builder.sendKeys(Keys.ENTER).perform();
    
    		// by id的用法
    		driver.findElement(By.id("ttbar-myjd")).click();
    		WebDriver window = DriverUtils.getWantDriver(driver,
    				Constant.jd_login_title);
    		// by name的用法
    		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();
    	}
    	@AfterTest
    	public void later(){
    		driver.close();
    	}
    
    }
    

    (3)让程序飞起来(运行testng.xml)

    截图329

  • 相关阅读:
    python---基础知识回顾(九)图形用户界面-------Tkinter
    python---基础知识回顾(八)数据库基础操作(sqlite和mysql)
    python---重点(设计模式)
    python---基础知识回顾(七)迭代器和生成器
    python---权限管理和菜单生成
    python---基础知识回顾(六)网络编程
    python---基础知识回顾(五)(python2.7和python3.5中的编码)
    CustomProgressBar
    android-square-progressbar-legacy
    AnimImageView
  • 原文地址:https://www.cnblogs.com/zhangshen/p/5550444.html
Copyright © 2020-2023  润新知