20180521

1、
package com.alipay.ats;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class LaunchIE {
private static WebDriver iewb=null;
private static DesiredCapabilities caps=null;
private String projectpath =System.getProperty("user.dir");

@BeforeClass
public void startIE(){
System.setProperty("webdriver.ie.driver",projectpath+"\\src\\test\\java\\com\\alipay\\ats\\IEDriverServer.64.exe");
caps=DesiredCapabilities.internetExplorer();
caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
caps.setCapability(InternetExplorerDriver.IE_SWITCHES,"-private");
caps.setCapability("ignoreZoomSetting",true);//IE浏览器放大放小
iewb=new InternetExplorerDriver(caps);
}
@Test
public void searchOnBaidu(){
iewb.manage().window().maximize();
iewb.get("http://www.baidu.com");
try{
Thread.sleep(5000);
}catch (InterruptedException e){
e.printStackTrace();
}
}
@AfterClass
public void releaseIEDriver(){
iewb.quit();
}
}
2、
package com.alipay.ats;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;

public class LaunchFF {
private WebDriver ffwb=null;
private FirefoxProfile firefoxProfile=null;
private String projectpath=System.getProperty("user.dir");
@BeforeClass
public void startFirefox(){
File firebug = new File(projectpath+"/tool/firebug-1.12.1-fx.xpi");
File firepath = new File(projectpath+"/tool/firepath-1.12.1-fx.xpi");
firefoxProfile=new FirefoxProfile();
try {
firefoxProfile.addExtension(firebug);
firefoxProfile.addExtension(firepath);
firefoxProfile.setPreference("webdriver.accept.untrusted.certs", "true");
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.12.1");
firefoxProfile.setPreference("network.proxy.type", 0);
firefoxProfile.setPreference("network.proxy.type", "10.1.1.0");
firefoxProfile.setPreference("network.proxy.http_port", 3128);
}catch (IOException e){
e.printStackTrace();
}
ffwb=new FirefoxDriver(firefoxProfile);
}
@Test
public void searchOnBaidu(){
ffwb.get("http://www.baidu.com");
//System.out.println(Locator.username1);
try {
Thread.sleep(5000);
}catch (InterruptedException e){
e.printStackTrace();
}
}
@AfterClass
public void releaseFFDriver(){
ffwb.quit();
}

}
3、
package com.alipay.ats;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.Arrays;

public class LaunchChrome {
private WebDriver chromewb=null;
private DesiredCapabilities caps=null;
private String projectpath=System.getProperty("user.dir");

@BeforeClass
public void startChrome(){
System.setProperty("webdriver.chrome.driver",projectpath+"\\src\\test\\java\\com\\alipay\\ats\\chromedriver.exe");
caps=DesiredCapabilities.chrome();
caps.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
chromewb=new ChromeDriver(caps);
}
@Test
public void searchOnBaidu(){
chromewb.get("http://www.baidu.com");
}
@AfterClass
public void releaseChromeDriver(){
chromewb.quit();
}
}
4、
package com.alipay.ats;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.io.IOException;
import java.util.Arrays;

public class Browsers {
public WebDriver driver=null;
private FirefoxProfile firefoxProfile=null;
private static DesiredCapabilities caps =null;
private String projectpath="";

public Browsers(BrowsersType browsersType){
switch (browsersType){
case firefox:
File firebug =new File(projectpath+"/tool/firebug-1.12.1-fx.xpi");
File firepath =new File(projectpath+"/tool/firepath-0.9.7-fx.xpi");
firefoxProfile = new FirefoxProfile();
try{
firefoxProfile.addExtension(firebug);
firefoxProfile.addExtension(firepath);
firefoxProfile.setPreference("webdriver.accept.untrusted.certs",true);
firefoxProfile.setPreference("extensions.firebug.currentVersion",1.12.1);
}catch (IOException e){
e.printStackTrace();
}
driver=new FirefoxDriver(firefoxProfile);
driver.manage().window().maximize();
break;
case ie:
System.setProperty("webdriver.ie.driver",projectpath+"/tool/IEDriverServer32.exe");
caps=DesiredCapabilities.internetExplorer();
caps.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS,false);
caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
caps.setCapability(InternetExplorerDriver.IE_SWITCHES,"-private");
caps.setCapability("ignoreZoomSetting",true);
driver = new InternetExplorerDriver(caps);
driver.manage().window().maximize();
break;
case chrome:
System.setProperty("webdriver.chrome.driver",projectpath+"/tool/chromedriver.exe");
caps=DesiredCapabilities.chrome();
caps.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
driver=new ChromeDriver(caps);
driver.manage().window().maximize();
break;
}
}
}
5、
package com.alipay.ats;

public enum BrowsersType {
firefox,ie,chrome;
}
6、
package com.alipay.ats;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;

public class TestBrowses {
private WebDriver driver;
private APIObject testlinkapi;
private String caseName;

@BeforeClass
public void beforeClass(){
Browsers browsers=new Browsers(BrowsersType.firefox);
driver=browsers.driver
}
@Test
public void start(){
caseName="DoOne";
driver.get("http:www.126.com");
driver.findElements(By.xpath("//input[@id='idInput']")).clear();
driver.findElement(By.xpath("//input[@id='idInput']")).sendKeys("FireflyAutomation");
driver.findElement(By.xpath("//input[@id='pwdInput']")).sendKeys("Firefly");
driver.findElement(By.xpath("//input[@id='pwdInput']")).submit();
Assert.assertEquals(true,true);
}
@AfterMethod
public void import2TestLink(ITestResult res){
testlinkapi.getAPI();
testlinkapi.getTestCases();
testlinkapi.executeTestCase(caseName,res.getStatus(),"Luter deose!");
}
}
7、
import org.testng.annotations.Test;

public class Practice3OnTestng {
@Test(groups = "submodule1")
public void testSubModule1(){
System.out.println("--testSubModule1--");
}
public void testSubModule2(){
System.out.println("--testSubModule2--");
}
public void testSubModule3(){
System.out.println("--testSubModule3--");
}
}
8、
<suite name="FireflyAutomation">
<test name="Practice1" preserve-order="true">
<groups>
<define name="submodule1"></define>
<define name="submodule2"></define>
<define name="submodule3"></define>
<define name="module1">
<include name="submodule1">
<include name="submodule2">
</define>
<define name="module2">
<include name="submodule2">
<include name="submodule3">
</define>
<run>
<include name="module1"></include>
</run>
</groups>
<classes>
<class name="practicetwo.groups.Practice3OnTestng"/>
</classes>
</test>
</suite>


























猜你喜欢

转载自www.cnblogs.com/xinxin1994/p/9068697.html
今日推荐