完整的第一个后台selenium Demo
来源:互联网 发布:linux怎么复制文件夹 编辑:程序博客网 时间:2024/05/02 06:27
package chrome;import static org.junit.Assert.*;import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Set;import java.util.concurrent.TimeUnit;import org.junit.Before;import org.junit.Test;import org.openqa.selenium.By;import org.openqa.selenium.Dimension;import org.openqa.selenium.Keys;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriverService;import org.openqa.selenium.interactions.Actions;import org.openqa.selenium.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;import org.openqa.selenium.support.ui.ExpectedConditions;import org.openqa.selenium.support.ui.Select;import org.openqa.selenium.support.ui.WebDriverWait;public class back_end { ChromeDriverService service; WebDriver driver; @Before public void before(){ service = new ChromeDriverService.Builder() .usingDriverExecutable(new File("D:\\Python\\WorkSpace\\chrome\\res\\chromedriver.exe")) .usingAnyFreePort().build(); try { service.start(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome()); } public void login() { driver.get("http://192.168.2.252/loyaltea-cms/login.jsp"); WebElement username=driver.findElement(By.xpath("//*[@id='username']")); username.sendKeys("admin"); WebElement pwd=driver.findElement(By.xpath("//*[@id='password']")); pwd.sendKeys("qctadmin"); WebElement yanzhengma=driver.findElement(By.id("code")); yanzhengma.sendKeys("8888"); WebElement login_btn=driver.findElement(By.xpath("//*[@id='login-form']/p[5]/button")); login_btn.click(); } //商城管理商城订单 @Test public void mallorder() throws InterruptedException{ login(); WebElement shangchengguanli=driver.findElement(By.xpath("//*[@id='navlist']/li[3]/a")); shangchengguanli.click(); //driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); Thread.sleep(4000); WebElement shangchengdingdan=driver.findElement(By.xpath("//*[@id='navlist']/li[3]/ul/li[6]/a/span")); int ok_size=driver.findElements(By.xpath("//*[@id='navlist']/li[3]/ul/li[6]/a/span")).size(); driver.findElements(By.xpath("//*[@id='navlist']/li[3]/ul/li[6]/a/span")).get(ok_size-1).click(); Thread.sleep(15000);// ArrayList<String> tabs2 = new ArrayList<String> (driver.getWindowHandles());// driver.switchTo().window(tabs2.get(0)); WebElement tab_2=driver.findElement(By.xpath("//*[@id='iframe-wraper']/iframe")); driver.switchTo().frame(1); Thread.sleep(3000); WebElement form= driver.findElement(By.xpath("//*[@id='orderTraceForm']")); //订单号 WebElement dingdanhao=driver.findElement(By.xpath("//*[@id='ordSeq']")); dingdanhao.sendKeys("201701180931380001"); WebElement chaxun=driver.findElement(By.xpath("//*[@id='serach']")); chaxun.click(); Thread.sleep(3000); //WebElement result1=driver.findElement(By.xpath("//*[@id='content']/tr/td[1]")); WebElement result = new WebDriverWait(driver, 10).until( ExpectedConditions.presenceOfElementLocated( By.xpath("//*[@id='content']/tr/td[1]") ) ); assertTrue(result.getText().contains("201701180931380001")); dingdanhao.clear(); //用户机构 WebElement yonghujigou=driver.findElement(By.xpath("//*[@id='mainPreson']")); yonghujigou.sendKeys("林"); chaxun.click(); Thread.sleep(3000); WebElement result_org = new WebDriverWait(driver, 10).until( ExpectedConditions.presenceOfElementLocated( By.xpath("//*[@id='content']/tr/td[1]") ) ); assertTrue(result_org.getText(),result_org.getText()!=null); yonghujigou.clear(); //工作室名称 WebElement gongzuoshimingcheng=driver.findElement(By.xpath("//*[@id='stuName']")); gongzuoshimingcheng.sendKeys("灰"); chaxun.click(); Thread.sleep(3000); WebElement result_studio = new WebDriverWait(driver, 10).until( ExpectedConditions.presenceOfElementLocated( By.xpath("//*[@id='content']/tr/td[1]") ) ); assertTrue(result_studio.getText(),result_studio.getText()!=null); gongzuoshimingcheng.clear(); //用户手机号 WebElement yonghushoujihao=driver.findElement(By.xpath("//*[@id='username']")); yonghushoujihao.sendKeys("15106061716"); chaxun.click(); Thread.sleep(3000); WebElement result_cellphone = new WebDriverWait(driver, 10).until( ExpectedConditions.presenceOfElementLocated( By.xpath("//*[@id='content']/tr/td[1]") ) ); assertTrue(result_cellphone.getText(),result_cellphone.getText()!=null); yonghushoujihao.clear(); //订单状态 Select select_zhuangtai = new Select(driver.findElement(By.xpath("//*[@id='ordState']"))); for (int i=0;i<8;i++){ select_zhuangtai.selectByIndex(i); System.out.println(select_zhuangtai.getOptions().get(i).getText()+"**********************************"); Thread.sleep(5000); WebElement element = driver.findElement(By.xpath("//*[@id='serach']")); Actions actions = new Actions(driver); actions.moveToElement(element).click().perform(); //chaxun.click(); Thread.sleep(10000); } }}
0 0
- 完整的第一个后台selenium Demo
- NDK_JNI 第一个完整的 小DEMO
- demo--CRUD不完整的后台
- 第一个jqGrid的demo
- 我的第一个demo!
- angularJS的第一个demo
- 【学习心得】-第一个完整的三角类
- 【学习心得】-第一个完整的三角类
- ListView的第一个item完整显示
- 我的第一个完整程序
- 初识struts2,第一个完整的例子
- 人生的第一个完整类
- 自己的第一个NDK的Demo
- 第一个Flash Builder4的Demo
- 自己的第一个游戏demo
- 我的第一个iOS Demo
- 我的第一个Retrofit小demo
- 我的第一个小demo
- HDU2485 Destroying the bus stations 最大流~Floyd+Dinic
- 流式布局(二)最后一个标签在右下角
- make 中打印变量
- 第21章 Ajax 与Comet(2)
- 使用MVP+RxAndroid+DroiBaaS打造云后台App—校园日记
- 完整的第一个后台selenium Demo
- AppStore打开后空白的解决办法
- 这是我学习COM遇到的几个基本问题其解决 黄森堂(vcmfc)著 1.我用ATL生成一个组件对象,我在COM中使用IDD_IEncrypt,这个在哪里写义,是啥?GUID? 答:IDD_IEncry
- php过滤数组空值
- iOS10相册相机闪退bug
- ubuntu为vlc-android编译 更新protoc为3+
- 微信小程序之图书管理系统(wepy版)
- Maven构建web项目默认web module2.3需要转变成3.0注意点
- Swift3.0-闭包、运算符重载