班级动态+班级资源库+AutoX模拟windows窗口脚本

This commit is contained in:
suntao 2017-01-13 18:24:49 +08:00
parent a2e4275397
commit fcc4344752
3 changed files with 268 additions and 16 deletions

View File

@ -2,6 +2,7 @@ package com.trustie.webdrive;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
@ -27,24 +28,29 @@ public class courseActive {
dr.findElement(By.xpath("//*[@id='sy_01']/a")).click();
String activeBannerName=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/div")).getText();
System.out.println("1.点击班级左侧导航处“动态”跳转至:"+activeBannerName);
//2验证班级动态数统计
String countCourseActive=dr.findElement(By.xpath("//*[@id='sy_01']/a/span")).getText();
System.out.println("2.当前班级有"+countCourseActive+"条动态");
//3验证动态头像链接至对应用户的个人主页
//3验证班级动态页面点击展开更多
dr.findElement(By.xpath("//*[@id='show_more_course_activities']")).click();
String iconShowActiveties=dr.findElement(By.xpath("//*[@id='show_more_course_activities']")).getText();
System.out.println("3.动态页面点击“"+iconShowActiveties+"”展开更多动态");
//4验证动态头像链接至对应用户的个人主页
String urlActiveHead=dr.findElement(By.xpath("//*[contains(@id,'user_activity')]/div[1]/div[1]/a")).getAttribute("href");
System.out.println("3.动态头像跳转至:"+urlActiveHead);
System.out.println("4.动态头像跳转至:"+urlActiveHead);
//4验证动态回复中用户头像返回对应用户的个人主页
//5验证动态回复中用户头像返回对应用户的个人主页
String urlActiveResponseHead=dr.findElement(By.xpath("//*[contains(@id,'reply_div')]/ul/li/div[1]/a")).getAttribute("href");
System.out.println("4.动态回复中头像跳转至:"+urlActiveResponseHead);
System.out.println("5.动态回复中头像跳转至:"+urlActiveResponseHead);
//5验证动态回复中用户名返回对应用户的个人主页
//6验证动态回复中用户名返回对应用户的个人主页
String urlActiveResponseUname=dr.findElement(By.xpath("//*[contains(@id,'reply_div')]/ul/li/div[2]/div[1]/a")).getAttribute("href");
System.out.println("5.动态回复中用户名跳转至:"+urlActiveResponseUname);
System.out.println("6.动态回复中用户名跳转至:"+urlActiveResponseUname);
//6验证动态过滤
//7验证动态过滤
WebElement elActiveFilter1=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/ul/li/a")); //定位动态过滤图标按钮
WebElement elAllActive=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/ul/li/ul/li/ul/li[1]/a")); //定位全部动态
Actions builder = new Actions(dr);
@ -57,7 +63,7 @@ public class courseActive {
e.printStackTrace();
}
String bannerNameAll=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/div")).getText();
System.out.println("6.1 筛选全部动态返回:"+bannerNameAll+"页面");
System.out.println("7.1 筛选全部动态返回:"+bannerNameAll+"页面");
WebElement elActiveFilter2=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/ul/li/a"));
WebElement elHomeWorkActive=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/ul/li/ul/li/ul/li[2]/a"));//定位作业动态
@ -70,7 +76,7 @@ public class courseActive {
e.printStackTrace();
}
String bannerNameHomework=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/div")).getText();
System.out.println("6.2 筛选作业动态返回:"+bannerNameHomework+"页面");
System.out.println("7.2 筛选作业动态返回:"+bannerNameHomework+"页面");
WebElement elActiveFilter3=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/ul/li/a"));
WebElement elNewsActive=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/ul/li/ul/li/ul/li[3]/a"));//定位作业动态
@ -83,7 +89,7 @@ public class courseActive {
e.printStackTrace();
}
String bannerNameNews=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/div")).getText();
System.out.println("6.3 筛选通知动态返回:"+bannerNameHomework+"页面");
System.out.println("7.3 筛选通知动态返回:"+bannerNameHomework+"页面");
WebElement elActiveFilter4=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/ul/li/a"));
WebElement elFilesActive=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/ul/li/ul/li/ul/li[4]/a"));//定位作业动态
@ -96,7 +102,7 @@ public class courseActive {
e.printStackTrace();
}
String bannerNameFiles=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/div")).getText();
System.out.println("6.4 筛选资源库动态返回:"+bannerNameFiles+"页面");
System.out.println("7.4 筛选资源库动态返回:"+bannerNameFiles+"页面");
try {
Thread.sleep(5000);
@ -115,7 +121,7 @@ public class courseActive {
e.printStackTrace();
}
String bannerNameBoards=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/div")).getText();
System.out.println("6.5 筛选论坛动态返回:"+bannerNameBoards+"页面");
System.out.println("7.5 筛选论坛动态返回:"+bannerNameBoards+"页面");
WebElement elActiveFilter6=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/ul/li/a"));
WebElement elFeedbackActive=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/ul/li/ul/li/ul/li[6]/a"));//定位作业动态
@ -128,7 +134,7 @@ public class courseActive {
e.printStackTrace();
}
String bannerNameFeedback=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/div")).getText();
System.out.println("6.6 筛选留言动态返回:"+bannerNameFeedback+"页面");
System.out.println("7.6 筛选留言动态返回:"+bannerNameFeedback+"页面");
try {
Thread.sleep(5000);
@ -147,9 +153,111 @@ public class courseActive {
e.printStackTrace();
}
String bannerNamePoll=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/div")).getText();
System.out.println("6.7 筛选问卷动态返回:"+bannerNamePoll+"页面");
System.out.println("7.7 筛选问卷动态返回:"+bannerNamePoll+"页面");
//切回全部动态
WebElement elActiveFilter8=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/ul/li/a")); //定位动态过滤图标按钮
WebElement elAllActive2=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/ul/li/ul/li/ul/li[1]/a")); //定位全部动态
builder.moveToElement(elActiveFilter8).perform();
builder.moveToElement(elAllActive2).click().perform();
//8验证动态回复框内默认tip显示我要回复
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
WebElement frameActiveResponse=dr.findElement(By.xpath("//*[contains(@id,'activity_post_reply')]/div[2]/div[2]/div[1]/form/div[3]/div[1]/iframe"));
dr.switchTo().frame(frameActiveResponse);
String tipActiveResponse=dr.findElement(By.xpath("/html/body")).getText();
System.out.println("8.动态回复框默认显示tip:"+tipActiveResponse);
//9验证动态一级回复
dr.findElement(By.xpath("/html/body")).sendKeys("班级动态回复内容");
dr.switchTo().defaultContent(); //切回主文档
dr.findElement(By.xpath("//*[contains(@id,'new_message_submit_btn')]")).click();
System.out.println("9.测试通过,动态成功一级回复");
//10验证动态二级回复框内默认tip
dr.findElement(By.xpath("//*[contains(@id,'reply_div')]/ul/li/div[2]/div[3]/div/span/span[2]/a")).click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
WebElement frameActiveSecResponse=dr.findElement(By.xpath("//*[contains(@id,'reply_to_message')]/div[2]/div[1]/form/div[3]/div[1]/iframe"));
dr.switchTo().frame(frameActiveSecResponse);
String tipActiveSecResponse=dr.findElement(By.xpath("//*[@id='hint']")).getText();
System.out.println("10.动态二级回复框内默认显示tip:"+tipActiveSecResponse);
//11验证班级动态二级回复
dr.findElement(By.xpath("/html/body")).sendKeys("动态二级回复");
dr.switchTo().defaultContent();
dr.findElement(By.xpath("//*[contains(@id,'new_message_submit_btn')]")).click();
System.out.println("11.测试通过,动态成功二级回复");
//12验证班级动态点赞取消点赞
WebElement elOpt=dr.findElement(By.xpath("//*[contains(@id,'praise_count')]/a/span[1]"));
String iconOpt=elOpt.getText();
System.out.println("12.1 班级动态点赞前显示为:"+iconOpt);
elOpt.click();
dr.navigate().refresh();
String iconCanceOpt=dr.findElement(By.xpath("//*[contains(@id,'praise_count')]/a/span[1]")).getAttribute("textContent");
System.out.println("12.2 班级动态取消点赞后显示为:"+iconCanceOpt);
//13验证班级动态回复点赞取消点赞
WebElement elSecOpt=dr.findElement(By.xpath("//*[contains(@id,'reply_div')]/ul/li/div[2]/div[3]/div/span/span[1]/a/span[1]"));
String iconSecOpt=elSecOpt.getText();
System.out.println("13.1 班级动态回复点赞前显示为:"+iconOpt);
elSecOpt.click();
dr.navigate().refresh();
String iconCanceSecOpt=dr.findElement(By.xpath("//*[contains(@id,'reply_div')]/ul/li/div[2]/div[3]/div/span/span[1]/a/span[1]")).getAttribute("textContent");
System.out.println("13.2 班级动态回复取消点赞后显示为:"+iconCanceSecOpt);
//14验证班级动态点击编辑跳转至动态编辑页面
WebElement elIconEditor=dr.findElement(By.xpath("//*[contains(@id,'user_activity')]/div[1]/div[2]/div[13]/ul/li"));
WebElement elEditor=dr.findElement(By.xpath("//*[contains(@id,'user_activity')]/div[1]/div[2]/div[13]/ul/li/ul/li[2]/a")); //悬浮窗口元素建议用xpath定位
builder.moveToElement(elIconEditor).perform();
builder.moveToElement(elEditor).click().perform();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String bannerName=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div/div")).getText();
System.out.println("14.点击编辑按钮后跳转至:"+bannerName+" 页面");
//15验证班级动态编辑
WebElement elTitleEdit=dr.findElement(By.xpath("//*[@id='news_title']"));
elTitleEdit.sendKeys(Keys.DELETE);
elTitleEdit.sendKeys("班级动态标题编辑");
WebElement iframeKeditor=dr.findElement(By.xpath("//*[@id='news_editor']/div[2]/div[2]/div[2]/iframe"));
dr.switchTo().frame(iframeKeditor);
WebElement elDescriptionEdit=dr.findElement(By.xpath("/html/body"));
elDescriptionEdit.sendKeys(Keys.DELETE);
elDescriptionEdit.sendKeys("班级动态描述编辑");
dr.switchTo().defaultContent(); //切回主文档
dr.findElement(By.xpath("//*[@id='news_editor']/div[6]/a[1]")).click(); //确认编辑动态
System.out.println("15.测试通过,班级动态成功编辑");
//动态发送删除和动态回复的发送删除确认弹框是用的浏览器自带弹框样式webdrive无法定位
//16验证动态编辑成功后跳转至动态详情页面
WebElement newBannerName=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/div"));
Boolean flag=newBannerName.isDisplayed();
//17验证回复数统计
String countResponse=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[3]/div[1]/div/sapn")).getText();
System.out.println("17、该动态下有"+countResponse+" 条回复");
//18验证点赞统计
String countOpt=dr.findElement(By.xpath("//*[contains(@id,'praise_count')]/a/span[2]")).getText();
System.out.println("18、该动态下有"+countOpt+" 个赞");
dr.quit(); //关闭浏览器窗口
}

View File

@ -0,0 +1,127 @@
package com.trustie.webdrive;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
public class files {
public static void main(String[] args) {
System.setProperty("webdriver.firefox.marionette","F:\\geckodriver-v0.11.1-win64\\geckodriver.exe");
WebDriver dr = new FirefoxDriver(); //声明webdrive对象
dr.get("https://ucloudtest.trustie.net"); //forefox访问uloudtest.trustie.net
//测试用户登录
dr.findElement(By.id("loginInButton")).click();
dr.findElement(By.name("username")).sendKeys("santo");
dr.findElement(By.name("password")).sendKeys("sa123456");
dr.findElement(By.className("new_login_submit")).click();
dr.get("https://ucloudtest.trustie.net/courses/672/files"); //进入测试班级
//1验证班级左侧导航点击资源库进入资源库页面
dr.findElement(By.xpath("//*[@id='sy_05']/a[1]")).click();
String bannerName=dr.findElement(By.xpath("//*[@id='resource_list']/div/div[1]/div")).getText();
System.out.println("1.点击班级左侧导航处资源库跳转至:"+bannerName+"页面");
//2验证班级左侧导航处资源数统计
String countFiles=dr.findElement(By.xpath("//*[@id='sy_05']/a[1]/span")).getText();
System.out.println("2.当前班级有:"+countFiles+"个资源");
//3验证左侧导航处+上的tip
String tipIconUploading=dr.findElement(By.xpath("//*[@id='sy_05']/a[2]")).getAttribute("title");
System.out.println("3.左侧导航处资源库+图标按钮上显示tip:"+tipIconUploading);
//4验证点击左侧导航+图标按钮弹出上传资源的弹框
dr.findElement(By.xpath("//*[@id='sy_05']/a[2]")).click();
String bombUploadingFiles=dr.findElement(By.xpath("//*[@id='popbox_upload']/div/h2")).getText();
System.out.println("4.点击左侧导航处+图标按钮弹出:"+bombUploadingFiles+"弹框");
//5验证资源上传框中附件描述输入框中默认tip
String tipFilesDescription=dr.findElement(By.xpath("//*[@id='popbox_upload']/div/div/form/div[6]/div[1]/input")).getAttribute("placeholder");
System.out.println("5.上传附件时附件描述输入框默认显示tip:"+tipFilesDescription);
//6验证点击左侧导航+上传资源功能通过第三方插件autoitX实现操作windows窗口
dr.findElement(By.xpath("//*[@id='popbox_upload']/div/div/form/div[4]/span[1]/button")).click();
//调用upfile.exe上传文件
try {
Runtime.getRuntime().exec("F://upfile.exe");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dr.findElement(By.xpath("//*[@id='popbox_upload']/div/div/form/div[6]/div[1]/input")).sendKeys("资源描述");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dr.findElement(By.xpath("//*[@id='submit_resource']")).click();
System.out.println("6.测试通过,成功上传资源");
dr.get("https://ucloudtest.trustie.net/courses/672/files");
//7验证资源搜索
dr.findElement(By.name("name")).sendKeys("Trustie");
dr.findElement(By.xpath("//*[@id='incourse']")).click();
String countAttachment=dr.findElement(By.xpath("//*[@id='attachment_count']")).getText();
System.out.println("7.当前班级有:"+countAttachment+"个包含Trustie关键字的资源");
//8验证成功上传资源后资源数统计自动加1
dr.findElement(By.xpath("//*[@id='name']")).clear();
dr.findElement(By.xpath("//*[@id='incourse']")).click();
String currentCountAttachment=dr.findElement(By.xpath("//*[@id='attachment_count']")).getAttribute("textContent");
System.out.println("8.测试通过,当前班级有:"+currentCountAttachment+"个资源与用例2比较自动加1");
//9验证置搜索条件为空返回全部资源列表
System.out.println("9.测试通过,搜索为空时返回全部资源列表");
//10验证公开资源私有资源统计
String countPublicFiles=dr.findElement(By.xpath("//*[@id='attachment_count_public']")).getText();
String countPrivateFiles=dr.findElement(By.xpath("//*[@id='attachment_count_private']")).getText();
System.out.println("10.当前班级有:"+countPublicFiles+""+countPrivateFiles);
//11验证资源上传者头像是否返回上传者个人主页
String urlUploaderHead=dr.findElement(By.xpath("//*[contains(@id,'resource_detail')]/div[1]/div/div[1]/a")).getAttribute("href");
System.out.println("11.上传者头像返回:"+urlUploaderHead);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//12验证添加资源标签
dr.findElement(By.xpath("//*[contains(@id,'resource_detail')]/div[1]/div/div[2]/div[6]/a")).click();
dr.findElement(By.xpath("//*[contains(@id,'tags_name')]")).sendKeys("资源测试标签");
dr.findElement(By.xpath("//*[contains(@id,'add_tag')]/input[5]")).click();
System.out.println("12.测试通过,资源已成功添加标签");
//13验证资源标签上默认显示的tip
String tipTagsEdit=dr.findElement(By.xpath("//*[contains(@id,'tags_show-Attachment')]/span[2]/a")).getAttribute("title");
System.out.println("13.资源标签上默认显示tip"+tipTagsEdit);
//14验证资源标签编辑
WebElement elTagsEdit = dr.findElement(By.xpath("//*[contains(@id,'tags_show-Attachment')]/span[2]/a"));
WebElement elNewTags=dr.findElement(By.xpath("//*[contains(@id,'tags_show-Attachment')]/span[2]/a"));
Actions builder = new Actions(dr);
builder.moveToElement(elTagsEdit).doubleClick().perform();
builder.moveToElement(elNewTags).sendKeys("资源标签编辑").sendKeys(Keys.ENTER).perform();
System.out.println("14.测试通过,资源标签已成功编辑");
// dr.quit(); //关闭浏览器窗口
}
}

View File

@ -0,0 +1,17 @@
;ControlFocus("title","text",controlID) Edit1=Edit instance 1
ControlFocus("文件上传", "","Edit1")
; Wait 10 seconds for the Upload window to appear
WinWait("[CLASS:#32770]","",10)
; Set the File name text on the Edit field
ControlSetText("文件上传", "", "Edit1", "C:\Users\zh\Desktop\Trustie.txt")
Sleep(2000)
; Click on the Open button
ControlClick("文件上传", "","Button1");