亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium web driver 配合使用TestNG
作者:網絡轉載 發布時間:[ 2014/4/3 9:05:09 ] 推薦標簽:Selenium TestNG

  4.下載并安裝 testng

  testng和junit相比為什么要使用testng
  1. testng 和junit功能基本相同testng支持suite,junit執行一大堆case,如果個別fail,只能所有case重跑
  而testng可以單獨跑
  2.testng能生成漂亮的測試報告,比較直觀
  添加一個testng case,復制一份,保存為
  openlinkTest1.java
package baidu;
import java.io.File;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import junit.framework.Assert;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class openlinkTest {
public static void snapshot(TakesScreenshot drivername, String filename)
{
// this method will take screen shot ,require two parameters ,one is driver name, another is file name
File scrFile = drivername.getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
try {
System.out.println("save snapshot path is:E:/"+filename);
FileUtils.copyFile(scrFile, new File("E:\"+filename));
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Can't save screenshot");
e.printStackTrace();
}
finally
{
System.out.println("screen shot finished");
}
}
@BeforeMethod
public void tearUp()
{
//    WebDriver driver = new ChromeDriver();
}
@Test
public static void runSelenium() throws InterruptedException
{
String URL="http://www.baidu.com";
Pattern p = Pattern.compile("http");
Matcher m = p.matcher(URL);
if(m.find())
{
System.out.println(URL);
}
System.setProperty("webdriver.chrome.driver", "E:\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get(URL);
//max size the browser
driver.manage().window().maximize();
/*
Navigation navigation = driver.navigate();
navigation.to(URL);*/
Thread.sleep(2000);
snapshot((TakesScreenshot)driver,"open_baidu.png");
//WebElement reg=driver.findElement(By.name("tj_reg"));
//reg.click();
//    WebElement keyWord = driver.findElement(By.id("kw1"));
//find the element
WebElement keyWord = driver.findElement(By.xpath("//input[@id='kw1']"));
keyWord.clear();
//send key words
keyWord.sendKeys("Selenium");
Thread.sleep(3000);
snapshot((TakesScreenshot)driver,"input_keyWord.png");
WebElement submit = driver.findElement(By.id("su1"));
System.out.println(submit.getLocation());
submit.click();
//System.out.println(driver.getWindowHandle());
Thread.sleep(5000);
// System.out.println(driver.getPageSource());
String pageSource=driver.getPageSource();
//  System.out.println(pageSource);
//WebElement link =driver.findElement(By.xpath(SELENIUM_LINK));
WebElement link =driver.findElement(By.xpath("//*[@id="1"]/h3/a"));     //*[@id="1"]/h3/a
link.click();
Thread.sleep(5000);
driver.switchTo().window(driver.getWindowHandles().toArray(new String[0])[1]);
//get page title
System.out.println(driver.getTitle());
Thread.sleep(5000);
//     navigation.back();
snapshot((TakesScreenshot)driver,"open_bake.png");
System.out.println(driver.getTitle()+" "+driver.getCurrentUrl());
Assert.assertEquals(driver.getTitle(),"Selenium - Web Browser Automation");
driver.quit();
}
@AfterMethod
public void tearDown()
{
//driver.quit();
System.out.println("------------END----------------------");
}
}

上一頁123下一頁
軟件測試工具 | 聯系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 欧美国产黄色 | 国产精品欧美亚洲韩国日本久久 | 成人自拍网站 | 人成在线视频 | 免费a资源| 精品欧美一区二区三区在线观看 | 国产成人综合精品一区 | 亚洲成人激情在线 | jizz日本zzz日本老师水 | 婷婷天堂 | 一级特黄a大片免费 | 在线99视频 | 真人午夜a一级毛片 | 中文字幕无线码欧美成人 | 日本 国产 欧美 | 亚洲一区在线免费 | 午夜欧美性欧美 | 国产天天射| 中文字幕网站 | 精品一区二区三区亚洲 | 九九色视频在线观看 | 一级a美女毛片 | 成人欧美精品一区二区不卡 | 91导航在线 | 国产性片在线 | 欧美成人午夜不卡在线视频 | 东京道区二区三区 | 尤物视频一区 | 外国一级黄色毛片 | 国产一区视频在线免费观看 | 国产精品一区高清在线观看 | 99riav国产精品 | 相泽亚洲一区中文字幕 | 人人干日日操 | 亚洲永久精品一区二区三区 | 午夜性刺激免费视频观看不卡专区 | 五月激情婷婷网 | 国产欧美日韩在线视频 | 国产欧美日韩精品综合 | 相泽亚洲一区中文字幕 | 丁香激情五月 |