Compare commits

...

4 Commits

8 changed files with 1087 additions and 0 deletions
Unified View
  1. +222
    -0
      temp_test/webdrive/course.java
  2. +264
    -0
      temp_test/webdrive/courseActive.java
  3. +123
    -0
      temp_test/webdrive/feedback.java
  4. +127
    -0
      temp_test/webdrive/files.java
  5. +127
    -0
      temp_test/webdrive/login.java
  6. +199
    -0
      temp_test/webdrive/news.java
  7. +8
    -0
      temp_test/webdrive/readme.txt
  8. +17
    -0
      temp_test/webdrive/upfile.au3

+ 222
- 0
temp_test/webdrive/course.java View File

@@ -0,0 +1,222 @@
package com.trustie.webdrive;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
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 course {
//webdrive切换浏览器
public static boolean switchToWindow(String windowTitle,WebDriver dr){
//浏览器窗口切换
boolean flag = false;
try {
// 将页面上所有的windowshandle放在入set集合当中
String currentHandle = dr.getWindowHandle();
Set<String> handles = dr.getWindowHandles();
for (String s : handles) {
if (s.equals(currentHandle))
continue;
else {
dr.switchTo().window(s);
// 和当前的窗口进行比较如果相同就切换到windowhandle
// 判断title是否和handles当前的窗口相同
if (dr.getTitle().contains(windowTitle)) {
flag = true;
System.out.println("Switch to window: "
+ windowTitle + " successfully!");
break;
} else
continue;
}
}
} catch (Exception e) {
System.out.printf("Window: " + windowTitle
+ " cound not found!", e.fillInStackTrace());
flag = false;
}
return flag;
}
public static void main(String[] args) {
//trustie login testing
System.setProperty("webdriver.firefox.marionette","F:\\geckodriver-v0.11.1-win64\\geckodriver.exe");
WebDriver dr = new FirefoxDriver(); //声明webdrive对象
dr.get("http://ucloudtest.trustie.net"); //firefox访问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();
//1.个人主页访问"课程社区",验证是否返回课程社区
String urlCoursesCommunity=dr.findElement(By.linkText("课程社区")).getAttribute("href");
// String urlCourses=dr.findElement(By.className("fl")).getAttribute("xpath=(//a[contains(@href, '/users/santo/courses')])[2]");
System.out.println("1.“课程社区”跳转至:"+urlCoursesCommunity);
//2.个人主页访问"课程",验证是否返回课程社区
String urlCourses=dr.findElement(By.linkText("课程")).getAttribute("href");
System.out.println("2.“课程”同样跳转至:"+urlCourses);
//3.验证个人主页班级数统计是否正确
String countCourses=dr.findElement(By.xpath("//div[2]/div/div[2]/ul/li/a/span")).getText();
System.out.println("3.当前用户有"+countCourses+"个课程");
//进入课程社区-课程列表
//4.验证课程下班级统计是否正确,验证课程列表"点击展开/收起全部班级"
dr.findElement(By.linkText("课程社区")).click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
course.switchToWindow("心里有一个宝宝-确实让创新更美好!", dr); //切换浏览器窗口
dr.findElement(By.id("user_course_list")).click();
String countCurrentCourses=dr.findElement(By.xpath("//ul[@id='syllabus_course_ul_1']/li[5]/a")).getText(); //动态id定位不到元素
dr.findElement(By.xpath("//ul[@id='syllabus_course_ul_1']/li[5]/a")).click(); //第一次点击展开
System.out.println("4.测试通过,"+countCurrentCourses);
dr.findElement(By.xpath("//ul[@id='syllabus_course_ul_1']/li[5]/a")).click(); //第二次点击收起
//5.验证课程列表中展开班级列表图标按钮上Tip
String tipExpandCourses=dr.findElement(By.xpath("//span[@onclick='expand_courses(1,4);']")).getAttribute("title");
System.out.println("5.课程列表中展开班级列表图标按钮上的tip是:"+tipExpandCourses);
//6.课程列表验证“点击展开/收起班级列表”
dr.findElement(By.xpath("//span[@onclick='expand_courses(1,4);']")).click(); //第一次点击收起,默认展开
dr.findElement(By.xpath("//span[@onclick='expand_courses(1,4);']")).click(); //第二次点击展开
System.out.println("6.测试通过,该课程可以成功展开/收起班级列表");
//7.验证课程列表中课程下默认显示的班级数
//List<WebElement> links=dr.findElements(By.xpath("//ul[@id='syllabus_course_ul_1']/li[*]/div/div/a")); //如何正则表达式表示xpath?
List<WebElement> links=dr.findElements(By.linkText("归档"));
int numDefault=links.size()-1;
System.out.println("7.课程列表中课程下默认显示"+numDefault+"个班级");
//8.验证课程列表中收藏班级图标按钮的tip
String tipIconSyFavorite=dr.findElement(By.className("icons_sy_favorite")).getAttribute("title");
dr.findElement(By.className("icons_sy_favorite")).click();
String tipIconSyStar=dr.findElement(By.xpath("//ul[@id='syllabus_course_ul_1']/li/span/a")).getAttribute("title");
System.out.println("8.1 课程列表中取消收藏班级图标按钮的tip是:"+tipIconSyFavorite);
System.out.println("8.2 课程列表中收藏班级图标按钮的tip是:"+tipIconSyStar);
//9.验证课程列表中隐藏班级!!同页面同一元素不好定位!!
//由于隐藏的是/courses/672,若左侧导航处第一个班级不是此班级,则隐藏的班级不显示
WebElement elHindCourse=dr.findElement(By.xpath("//ul[@id='user_courses_li']/li/p/a"));
String urlFirstCourse=elHindCourse.getAttribute("href");
if(urlFirstCourse!="/courses/672")
System.out.println("9.测试通过,隐藏的班级已隐藏");
else
System.out.println("9.测试失败,隐藏的班级仍显示");
//10.验证班级归档图标按钮上tip
WebElement elArchive=dr.findElement(By.linkText("归档"));
WebElement tipArchive=dr.findElement(By.xpath("//ul[@id='syllabus_course_ul_1']/li/div[2]/div/p")); //悬浮窗口元素建议用xpath定位
Actions builder1 = new Actions(dr);
builder1.moveToElement(elArchive).perform();
String tipA=dr.findElement(By.xpath("//ul[@id='syllabus_course_ul_1']/li/div[2]/div/p")).getText();
System.out.println("10.归档按钮上的tip是:"+tipA);
//11.验证点击归档是否弹出确认是否归档的提示弹框
dr.findElement(By.linkText("归档")).click();
try {
Thread.sleep(3000);
} catch (InterruptedException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
WebElement elHintFrame=dr.findElement(By.xpath("//*[@id='muban_popup_box']/div[2]/div/p"));
if(elHintFrame.isDisplayed())
System.out.println("11.测试通过,点击归档成功弹出是否确认归档的提示弹框");
else
System.out.println("11.点击归档未弹出提示弹框");
//12.确认归档、取消归档
dr.findElement(By.xpath("//*[@id='muban_popup_box']/div[2]/div/a[1]")).click(); //取消归档
dr.findElement(By.linkText("归档")).click();
dr.findElement(By.xpath("//*[@id='muban_popup_box']/div[2]/div/a[2]")).click(); //确认归档
// dr.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
//设置5秒的等待时间
//否则可能由于点击速度过快,加上网络延迟的影响,页面没有加载出来就需要点击页面上的元素导致定位失败
try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
dr.findElement(By.xpath("//*[@id='muban_popup_box']/div[2]/div/a")).click();
System.out.println("12.测试通过,测试班级已成功归档");
//13.验证“恢复”归档按钮上的tip
dr.findElement(By.linkText("归档管理")).click();
WebElement elRecover=dr.findElement(By.linkText("恢复"));
Actions builder2 = new Actions(dr);
builder2.moveToElement(elRecover).perform();
String tipR=dr.findElement(By.xpath("//*[@id='syllabus_course_ul_1']/li/div[2]/div/p")).getText();
System.out.println("13.恢复按钮上的tip是:"+tipR);
//14.验证点击恢复归档按钮的提示弹框,及打印出提示信息
dr.findElement(By.linkText("恢复")).click();
WebElement elRenew=dr.findElement(By.xpath("//*[@id='muban_popup_box']/div[2]/div/p"));
if(elRenew.isDisplayed())
System.out.println("14.1 测试通过,点击恢复按钮成功弹出是否确认恢复班级的提示弹框");
else
System.out.println("14.点击归档未弹出提示弹框");
String tipRenew=dr.findElement(By.xpath("//*[@id='muban_popup_box']/div[2]/div/p")).getText();
System.out.println("14.2 点击恢复按钮弹出是否确认恢复的弹框,并提示:"+tipRenew);
//16.归档管理、恢复归档
dr.findElement(By.xpath("//*[@id='muban_popup_box']/div[2]/div/a[1]")).click(); //取消恢复
dr.findElement(By.linkText("恢复")).click();
dr.findElement(By.xpath("//*[@id='muban_popup_box']/div[2]/div/a[2]")).click(); //确认恢复
System.out.println("16.测试通过,可成功确认/取消恢复归档");
//17.确认恢复归档后,验证是否弹出“已恢复”的提示弹框
//设置5秒的等待时间
try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
WebElement elConfirmRenew=dr.findElement(By.xpath("//*[@id='muban_popup_box']/div[2]/div/p"));
if(elConfirmRenew.isDisplayed())
System.out.println("17.1 测试通过,确认恢复归档后,弹出"+elConfirmRenew.getText());
else
System.out.println("17.1 测试失败");
dr.findElement(By.xpath("//*[@id='muban_popup_box']/div[2]/div/a")).click(); //确认恢复
System.out.println("17.2 被归档班级已成功恢复");
//18.验证返回课程列表
dr.findElement(By.linkText("返回")).click();
WebElement elCourse=dr.findElement(By.xpath("//*[@id='syllabus_course_ul_1']/li[1]/div[1]/div[1]/a"));
if(elCourse.isDisplayed())
System.out.println("18.返回课程列表,恢复的班级重新显示在课程列表中");
else
System.out.println("测试失败");
try{
Thread.sleep(3000);
} catch(InterruptedException e){
// TODO Auto-generated catch block
e.printStackTrace();
}
dr.quit(); //关闭浏览器窗口
}
}
//归档管理中恢复归档

+ 264
- 0
temp_test/webdrive/courseActive.java View File

@@ -0,0 +1,264 @@
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;
import org.openqa.selenium.interactions.Actions;
public class courseActive {
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"); //进入测试班级
//1、验证点击左侧导航处“动态”跳转至班级动态页面
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、验证班级动态页面“点击展开更多”
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("4.动态头像跳转至:"+urlActiveHead);
//5、验证动态回复中用户头像返回对应用户的个人主页
String urlActiveResponseHead=dr.findElement(By.xpath("//*[contains(@id,'reply_div')]/ul/li/div[1]/a")).getAttribute("href");
System.out.println("5.动态回复中头像跳转至:"+urlActiveResponseHead);
//6、验证动态回复中用户名返回对应用户的个人主页
String urlActiveResponseUname=dr.findElement(By.xpath("//*[contains(@id,'reply_div')]/ul/li/div[2]/div[1]/a")).getAttribute("href");
System.out.println("6.动态回复中用户名跳转至:"+urlActiveResponseUname);
//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);
builder.moveToElement(elActiveFilter1).perform();
builder.moveToElement(elAllActive).click().perform();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String bannerNameAll=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/div")).getText();
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"));//定位“作业动态”
builder.moveToElement(elActiveFilter2).perform();
builder.moveToElement(elHomeWorkActive).click().perform();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String bannerNameHomework=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/div")).getText();
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"));//定位“作业动态”
builder.moveToElement(elActiveFilter3).perform();
builder.moveToElement(elNewsActive).click().perform();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String bannerNameNews=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/div")).getText();
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"));//定位“作业动态”
builder.moveToElement(elActiveFilter4).perform();
builder.moveToElement(elFilesActive).click().perform();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String bannerNameFiles=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/div")).getText();
System.out.println("7.4 筛选资源库动态返回:"+bannerNameFiles+"页面");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
WebElement elActiveFilter5=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/ul/li/a"));
WebElement elBoardsActive=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/ul/li/ul/li/ul/li[5]/a"));//定位“作业动态”
builder.moveToElement(elActiveFilter5).perform();
builder.moveToElement(elBoardsActive).click().perform();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String bannerNameBoards=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/div")).getText();
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"));//定位“作业动态”
builder.moveToElement(elActiveFilter6).perform();
builder.moveToElement(elFeedbackActive).click().perform();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String bannerNameFeedback=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/div")).getText();
System.out.println("7.6 筛选留言动态返回:"+bannerNameFeedback+"页面");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
WebElement elActiveFilter7=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/ul/li/a"));
WebElement elPollActive=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/ul/li/ul/li/ul/li[7]/a"));//定位“作业动态”
builder.moveToElement(elActiveFilter7).perform();
builder.moveToElement(elPollActive).click().perform();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String bannerNamePoll=dr.findElement(By.xpath("/html/body/div[4]/div[2]/div[2]/div/div[1]/div")).getText();
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(); //关闭浏览器窗口
}
}

+ 123
- 0
temp_test/webdrive/feedback.java View File

@@ -0,0 +1,123 @@
package com.trustie.webdrive;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class feedback {
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/feedback"); //进入测试班级
//1.验证班级左侧导航“留言”返回留言页面
String urlFeedback=dr.findElement(By.xpath("//*[@id='sy_06']/a[1]")).getAttribute("href");
System.out.println("1.班级左侧导航处留言返回:"+urlFeedback);
//2.验证班级留言页面顶部有“用户留言”字样
String bannerFeedback=dr.findElement(By.xpath("//*[@id='mesLabel']")).getText();
System.out.println("2.班级留言页面顶部显示“"+bannerFeedback+"”字样");
//3.验证班级左侧导航处留言数统计
String countCoursesJour=dr.findElement(By.xpath("//*[@id='course_jour_count']")).getText();
System.out.println("3.该班级中有"+countCoursesJour+"条留言");
//4.验证留言内容为空时,是否给出“内容不能为空”的提示信息
dr.findElement(By.linkText("留言")).click();
String tipJourNull=dr.findElement(By.xpath("//*[@id='jour_content_span']")).getText();
System.out.println("4.留言内容为空时,提示:"+tipJourNull);
//5.验证取消班级留言
WebElement frameFeedbackKeditor=dr.findElement(By.xpath("//*[@id='course_feedback_new']/li/div[1]/div[2]/iframe"));
dr.switchTo().frame(frameFeedbackKeditor);
dr.findElement(By.xpath("/html/body")).sendKeys("班级留言内容");
dr.switchTo().defaultContent(); //切回主文档
dr.findElement(By.xpath("//*[@id='course_feedback_new']/a[2]")).click();
dr.switchTo().frame(frameFeedbackKeditor);
String jour=dr.findElement(By.xpath("/html/body")).getText();
System.out.println("5.留言内容为“"+jour+"”(预期输出为空),若留言内容为空,则测试通过,取消留言后,留言内容被自动清空");
//6.验证正常留言
dr.findElement(By.xpath("/html/body")).sendKeys("班级留言内容");
dr.switchTo().defaultContent();
dr.findElement(By.xpath("//*[@id='submit_feedback_user']")).click();
dr.findElement(By.xpath("//*[@id='submit_feedback_user']")).click();
System.out.println("6.测试通过,已成功留言");
//7.验证成功留言后,留言数统计是否自动加1
//dr.navigate().refresh();
WebElement elCountJour=dr.findElement(By.xpath("//*[@id='course_jour_count']"));
String textCountJour=elCountJour.getAttribute("textContent");
System.out.println("7.当前留言数为:"+textCountJour+"(与用例3相比较,留言数统计是否自动加1)");
//8.验证留言头像是否链接至对应用户的个人主页
String urlHead=dr.findElement(By.xpath("//*[contains(@id,'user_activity')]/div[1]//div[1]/a")).getAttribute("href");
System.out.println("8.当前留言人头像跳转至:"+urlHead);
//9.验证留言用户名是否链接至对应用户的个人主页
String urlUsername=dr.findElement(By.xpath("//*[contains(@id,'user_activity')]/div[1]/div[2]/div[1]/a[1]")).getAttribute("href");
System.out.println("9.当前留言用户名跳转至:"+urlUsername);
//当前版本留言回复为空时不再给出提示,而是收起“发送”按钮
//10.验证留言回复为空时,是否给出回复内容不能为空的提示
WebElement iframeresponse=dr.findElement(By.xpath("//*[contains(@id,'activity_post_reply')]/div[2]/div[2]/div[1]/form/div[3]/div[1]/iframe"));
dr.switchTo().frame(iframeresponse);
dr.findElement(By.xpath("/html/body")).click();
dr.switchTo().defaultContent();
WebElement subBtn=dr.findElement(By.xpath("//a[contains(text(),'发送')]"));
subBtn.click();
if(subBtn.isDisplayed())
System.out.println("10.测试失败");
else
System.out.println("10.测试通过,留言回复为空则收起“发送”按钮");
//11.验证正常留言一级回复
//dr.findElement(By.xpath("//*[contains(@id,'word_li')]/div[2]/div[2]/a[1]")).click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//WebElement frameReplyKeditor=dr.findElement(By.xpath("//*[contains(@id,'project_respond_form')]/form/div[2]/div[1]/iframe"));
dr.switchTo().frame(iframeresponse);
dr.findElement(By.xpath("/html/body")).sendKeys("班级留言一级回复");
dr.switchTo().defaultContent();
dr.findElement(By.xpath("//a[contains(text(),'发送')]")).click();
System.out.println("11.测试通过,已成功一级回复");
//12.验证留言赞、取消赞
String iconCanceFavour=dr.findElement(By.xpath("//*[contains(@id,'praise_count')]/a/span[1]")).getText();
System.out.println("12.1 未赞的状态为:"+iconCanceFavour);
dr.findElement(By.xpath("//*[contains(@id,'praise_count')]/a/span[1]")).click();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String iconFavour=dr.findElement(By.xpath("//*[contains(@id,'praise_count')]/a/span[1]")).getText();
System.out.println("12.2 已赞的状态显示为:"+iconFavour);
dr.quit(); //关闭浏览器窗口
}
}

+ 127
- 0
temp_test/webdrive/files.java 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(); //关闭浏览器窗口
}
}

+ 127
- 0
temp_test/webdrive/login.java View File

@@ -0,0 +1,127 @@
package com.trustie.webdrive;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
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 login {
public static void main(String[] args) {
//trustie login testing
System.setProperty("webdriver.firefox.marionette","F:\\geckodriver-v0.11.1-win64\\geckodriver.exe");
WebDriver dr = new FirefoxDriver(); //声明webdrive对象
dr.get("http://ucloudtest.trustie.net"); //forefox访问uloudtest.trustie.net
//1.验证未登录页面title是否正确
String title1=dr.getTitle();
System.out.println("1.未登录时返回:"+title1+" 页面");
//2.验证输入框内tip
String usernameTip=dr.findElement(By.name("username")).getAttribute("placeholder");
String pswTip=dr.findElement(By.name("password")).getAttribute("placeholder");
System.out.println("2.1 登录名input内tip是:"+usernameTip);
System.out.println("2.2 密码input内tip是:"+pswTip);
//3.置登录名和密码为空,点击登录按钮,并输出提示信息
dr.findElement(By.id("loginInButton")).click();
dr.findElement(By.className("new_login_submit")).click();
WebElement element1=dr.findElement(By.className("new_login_error"));
String a=element1.getText();
System.out.println("3.登录名和密码为空时提示:"+a);
//4.验证用户名和密码均为空格
dr.findElement(By.name("username")).sendKeys(" ");
dr.findElement(By.name("password")).sendKeys(" ");
dr.findElement(By.className("new_login_submit")).click();
WebElement elTipPswSpace=dr.findElement(By.className("new_login_error"));
String tipPswSpace=elTipPswSpace.getText();
System.out.println("4.输入用户名和密码均为空格时提示:"+tipPswSpace);
//5.置密码为空,点击登录按钮,并输入出提示信息
dr.findElement(By.name("username")).sendKeys("santo");
dr.findElement(By.className("new_login_submit")).click();
WebElement element2=dr.findElement(By.className("new_login_error"));
String b=element2.getText();
System.out.println("5.密码为空时提示:"+b);
//6.输入错误密码,点击登录按钮,并输入出提示信息
dr.findElement(By.name("username")).sendKeys("santo");
dr.findElement(By.name("password")).sendKeys("123456");
dr.findElement(By.className("new_login_submit")).click();
WebElement element3=dr.findElement(By.className("new_login_error"));
String c=element3.getText();
System.out.println("6.输入错误密码时提示:"+c);
//7.测试不存在的用户名和密码
dr.findElement(By.name("username")).sendKeys("admin");
dr.findElement(By.name("password")).sendKeys("admin");
dr.findElement(By.className("new_login_submit")).click();
WebElement elInvalid=dr.findElement(By.className("new_login_error"));
String tipInvalid=elInvalid.getText();
System.out.println("7.输入不存在的用户名和密码时提示:"+tipInvalid);
//页面焦点是否控制在第一个输入框内
//测试用户名和密码的长度(测试注册功能时验证,因为只要可以注册的就都可以登录)
//测试用户登录失败多次后,系统是否会锁住,或提示相应的警告信息(平台未做此类信息的验证)
//8.验证用户名和密码是否区分大小写
dr.findElement(By.name("username")).sendKeys("SANTO");
dr.findElement(By.name("password")).sendKeys("SA123456");
dr.findElement(By.className("new_login_submit")).click();
WebElement elCaseSensitive=dr.findElement(By.className("new_login_error"));
String tipCaseSensitive=elCaseSensitive.getText();
System.out.println("8.输入用户名和密码为错误的大写时提示:"+tipCaseSensitive);
//9.验证正确的管理员用户名和密码正常登录
dr.findElement(By.name("username")).sendKeys("innov");
dr.findElement(By.name("password")).sendKeys("9*x2km&a#s6m");
dr.findElement(By.className("new_login_submit")).click();
System.out.println("9.管理员账号已成功登录!");
//10.验证正常退出登录
WebElement elUserLogo=dr.findElement(By.id("nh_user_logo"));
WebElement elLogout=dr.findElement(By.xpath("//a[contains(text(),'退出')]")); //悬浮窗口元素建议用xpath定位
Actions builder = new Actions(dr);
builder.moveToElement(elUserLogo).perform();
builder.moveToElement(elLogout).click().perform();
System.out.println("10.已成功退出登录!");
// Action serierofAction =
// builder.moveToElement(elUserLogo).moveToElement(elLogout).click().build();
// dr.findElement(By.linkText("退出")).click(); //悬浮窗口元素用linkText属性定位时失败
// serierofAction.perform();
dr.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); //设置页面加载等待时间
//11.验证普通用户正常登录
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();
System.out.println("11.普通账号已成功登录!");
//return linkUsername.isDisplayed();
//12.成功登录后,验证当前用户url中是否包含用户名
String targeturl=dr.getCurrentUrl();
System.out.println("12.当前个人主页url中包含用户id:"+targeturl);
//13.成功登录后,验证是否返回当前用户首页
String title2=dr.getTitle();
System.out.println("13.当前返回 "+title2+" 的个人主页");
try{
Thread.sleep(3000);
} catch(InterruptedException e){
// TODO Auto-generated catch block
e.printStackTrace();
}
dr.quit(); //关闭浏览器窗口
}
}

+ 199
- 0
temp_test/webdrive/news.java View File

@@ -0,0 +1,199 @@
package com.trustie.webdrive;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class news {
public static void main(String[] args) {
//trustie login testing
//assertEquals(driver.findElement(By.id("pageNumber")).getText(), ("2"));
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"); //进入测试班级
//1.验证点击左侧导航处“通知”返回通知列表
dr.findElement(By.xpath("//*[@id='sy_04']/a[1]")).click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String GuideNewsLists=dr.findElement(By.xpath("//*[@id='course-newslist']/div/p")).getText();
System.out.println("1.点击左侧导航处“通知”返回:"+GuideNewsLists);
//2.验证左侧导航处通知统计
String CountNews=dr.findElement(By.xpath("//*[@id='sy_04']/a[1]/span")).getText();
System.out.println("2.该班级下有"+CountNews+"条通知");
//3.验证通知列表中通知描述输入框是默认收起的
//涉及到切换iframe、先定位到iframe、再切到这个iframe里面
// WebElement frameElement=dr.findElement(By.xpath("//*[@id='news_editor']/div[2]/div[2]/div[2]/iframe"));
// dr.switchTo().frame(frameElement);
// WebElement inputDescription=dr.findElement(By.xpath("/html/body"));
WebElement elEditor=dr.findElement(By.xpath("//*[@id='news_editor']/div[2]/div[2]/div[2]/textarea"));
if(elEditor.isDisplayed())
System.out.println("3.测试失败");
else
System.out.println("3.测试通过,进入班级通知列表,通知描述框默认隐藏");
//4.验证通知列表分页默认显示的通知条数,通知列表中每页显示的通知条数=“回复”个数
List<WebElement> links=dr.findElements(By.xpath("//span[contains(text(),'回复')]"));
System.out.println("4.通知列表每页显示"+links.size()+"条通知");
//5.验证通知列表分页功能
dr.findElement(By.xpath("//*[@id='pages']/li[3]/a")).click(); //点击第2页
dr.findElement(By.linkText("下一页")).click(); //点击下一页,返回第一页
System.out.println("5.测试通过,正常翻页");
//6.验证通知标题输入框内tip
String tipNewsTitle=dr.findElement(By.id("news_title")).getAttribute("placeholder");
System.out.println("6.通知标题输入框内tip是:"+tipNewsTitle);
//7.验证通知标题、描述为空时,是否给出相关提示信息
dr.findElement(By.id("news_title")).click();
dr.findElement(By.xpath("//*[@id='news_editor']/div[6]/a[1]")).click();
String tipTitleNull=dr.findElement(By.id("title_notice_span")).getText();
dr.findElement(By.id("news_title")).sendKeys("班级通知的标题");
dr.findElement(By.xpath("//*[@id='news_editor']/div[6]/a[1]")).click();
String tipDescriptionNull=dr.findElement(By.id("description_notice_span")).getText();
System.out.println("7.1 通知标题为空时,提示:"+tipTitleNull);
System.out.println("7.2 通知描述为空时,提示:"+tipDescriptionNull);
dr.findElement(By.id("news_title")).clear(); //清空标题输入的内容
//8.验证确认、取消新建通知,涉及到切换Iframe定位元素
dr.findElement(By.id("news_title")).sendKeys("班级通知的标题");
WebElement frameKeElement=dr.findElement(By.xpath("//*[@id='news_editor']/div[2]/div[2]/div[2]/iframe"));
dr.switchTo().frame(frameKeElement);
dr.findElement(By.xpath("/html/body")).sendKeys("班级通知描述");
dr.switchTo().defaultContent(); //切回主文档
dr.findElement(By.xpath("//*[@id='news_editor']/div[6]/a[1]")).click();
System.out.println("8.测试通过,成功新建通知");
//9.验证成功新建通知后,左侧导航通知统计是否+1
String CountNewNews=dr.findElement(By.xpath("//*[@id='sy_04']/a[1]/span")).getText();
System.out.println("9.新建通知后,左侧导航处通知统计变为:"+CountNewNews+"(和用例2比较)");
//验证更新时间是否正确
//10.验证点击通知列表中通知标题进入通知详情页面
dr.findElement(By.xpath("//*[@id='course-newslist']/div/div[2]/div[1]/div[1]/a")).click();
String newsUrl=dr.getCurrentUrl();
System.out.println("10.点击通知列表中通知标题返回:"+newsUrl);
/*
//验证班级通知发送功能
WebElement elNewsIcon=dr.findElement(By.xpath("//*[contains(@id,'message_setting')]/ul/li"));
WebElement elSend=dr.findElement(By.xpath("//*[contains(@id,'message_setting')]/ul/li/ul/li[1]/a")); //悬浮窗口元素建议用xpath定位
Actions builder = new Actions(dr);
builder.moveToElement(elNewsIcon).click().perform();
builder.moveToElement(elSend).click().perform();
//验证点击发送按钮后,是否弹出选择发送目标的弹框
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
WebElement elSendBounced=dr.findElement(By.xpath("//*[@id='ajax-modal']/div/div[1]/div[1]"));
if(elSendBounced.isDisplayed())
System.out.println("测试通过,点击发送按钮后弹出选择发送目标的弹框");
else
System.out.println("测试失败");
dr.findElement(By.xpath("//*[@id='course_list_form']/div[2]/div/ul[1]/li[1]/input")).click();//选择班级进行发送
dr.findElement(By.xpath("//*[@id='course_list_form']/div[4]/div[1]/input")).click(); //点击确定按钮,确定发送
//...验证确定发送后,是否弹出“发送成功”的提示信息(此处提示弹框是浏览器自带的弹框样式,无法定位)
//...由于webdrive无法定位浏览器自带样式弹框,即点击确定按钮后,无法确认点击“发送成功”的提示弹框,故“发送”功能无法自动化
*/
//11.验证点击编辑后是否进入编辑页面
WebElement elNewsIcon=dr.findElement(By.xpath("//*[contains(@id,'message_setting')]/ul/li"));
WebElement elEdit=dr.findElement(By.xpath("//*[contains(@id,'message_setting')]/ul/li/ul/li[2]/a")); //悬浮窗口元素建议用xpath定位
Actions builder = new Actions(dr);
builder.moveToElement(elNewsIcon).click().perform();
builder.moveToElement(elEdit).click().perform();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String NewsBannerName=dr.findElement(By.xpath("//*[contains(text(),'编辑通知')]")).getText();
System.out.println("11.点击编辑按钮进入:"+NewsBannerName+"页面");
//12.验证通知编辑功能
dr.findElement(By.id("news_title")).sendKeys("编辑班级通知的标题");
WebElement elframeKe=dr.findElement(By.xpath("//*[@id='news_editor']/div[2]/div[2]/div[2]/iframe"));
dr.switchTo().frame(elframeKe);
dr.findElement(By.xpath("/html/body")).sendKeys("编辑班级通知描述");
dr.switchTo().defaultContent(); //切回主文档
dr.findElement(By.xpath("//*[@id='news_editor']/div[6]/a[1]")).click();
System.out.println("12.测试通过,班级通知已成功编辑");
//13.验证通知回复内容为空时,是否提示“评论不能为空”
dr.findElement(By.xpath("//*[@id='news_submit_comment']")).click();
String tipCommerNull=dr.findElement(By.xpath("//*[@id='add_reply_news']")).getText();
System.out.println("13.通知回复内容为空时,提示:"+tipCommerNull);
//14.验证通知一级回复
WebElement elKeEdit=dr.findElement(By.xpath("//*[@id='news_comment']/div/div[2]/iframe"));
dr.switchTo().frame(elKeEdit);
dr.findElement(By.xpath("/html/body")).sendKeys("通知一级回复");
dr.switchTo().defaultContent(); //切回主文档
dr.findElement(By.xpath("//*[@id='news_submit_comment']")).click();
System.out.println("14.测试通过,已对通知进行一级回复");
//15.验证二级回复框内tip
dr.findElement(By.xpath("//*[contains(@id,'reply_div')]/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 elSecKeEdit=dr.findElement(By.xpath("//*[@id='new_form']/div[3]/div[1]/iframe"));
dr.switchTo().frame(elSecKeEdit);
String tipSecCommerNull=dr.findElement(By.xpath("//*[@id='hint']")).getText();
System.out.println("15.通知二级回复框内默认显示tip:"+tipSecCommerNull);
//16.验证通知二级回复
dr.findElement(By.xpath("/html/body")).sendKeys("通知二级回复");
dr.switchTo().defaultContent(); //切回主文档
dr.findElement(By.xpath("//*[contains(@id,'new_message_submit_btn')]")).click();
System.out.println("16.测试通过,已对通知进行二级回复");
/* //...验证通知回复删除,删除通知回复弹出的是浏览器自带的样式弹框,webdrive无法定位
WebElement elDeleteCommer=dr.findElement(By.xpath("//*[contains(@id,'delete_reply']"));
Actions builderDeleteCommer = new Actions(dr);
builderDeleteCommer.moveToElement(elDeleteCommer).click().perform(); */
//17.验证通知赞、取消赞
dr.findElement(By.xpath("//*[contains(@id,'praise_count')]/a/span[1]")).click(); //赞
dr.findElement(By.xpath("//*[contains(@id,'praise_count')]/a/span[1]")).click(); //取消赞
System.out.println("17.测试通过,已对通知进行赞、取消赞");
//18.验证通知回复赞、取消赞
dr.findElement(By.xpath("//*[contains(@id,'reply_div')]/li/div[2]/div[3]/div/span/span[1]/a/span[1]")).click(); //赞
dr.findElement(By.xpath("//*[contains(@id,'reply_div')]/li/div[2]/div[3]/div/span/span[1]/a/span[1]")).click(); //取消赞
System.out.println("18.测试通过,已对通知回复进行赞、取消赞");
dr.quit(); //关闭浏览器窗口
}
}

+ 8
- 0
temp_test/webdrive/readme.txt View File

@@ -0,0 +1,8 @@
测试代码说明:
流程:
Selenium grid+java(或Python或Ruby)编写测试脚本,并在代码中插入TestNG annotation
将测试信息添加到testng.xml文件或build.xml文件
运行TestNG
Jenkins持续集成(评审通过)
资源库上传文件弹框改版了,资源库脚本尚未更新

+ 17
- 0
temp_test/webdrive/upfile.au3 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");

Loading…
Cancel
Save