wordpress登录、修改、删除、查看代码记录
wordpress
登录,新增、修改、删除、查看,页面代码如下
package info.itest.www; import static org.junit.Assert.*; import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions; public class RunAll {
WebDriver dr; @Before
public void setUp() throws Exception {
System.out.println("Start test"); // 使用firefox浏览器,打开指定路径的firefox浏览器
System.setProperty("webdriver.firefox.bin",
"D:/Mozilla Firefox/firefox.exe");
this.dr = new FirefoxDriver(); //使用chrome浏览器
//this.dr = new ChromeDriver(); } @After
public void tearDown() throws Exception {
System.out.println("End test");
this.dr.quit(); } @Test
public void testLogin() {
System.out.println("login test"); String username = "admin";
String password = "123456";
//定义登录url
this.Login(username, password); //断言登录用户
assertTrue(dr.getCurrentUrl().contains(username)); //断言用户是否登录成功
WebElement adminLink = dr.findElement(By.id("wp-admin-bar-my-account")).findElement(By.className("ab-item"));
assertTrue(adminLink.getText().contains(username)); } @Test
public void testCreatePost(){
System.out.println("create test"); String username = "admin";
String passwd = "123456";
//登录
this.Login(username, passwd); String title = "Test title" + System.currentTimeMillis();
this.createPost(title); dr.get("http://localhost/wordpress/");
WebElement first_post = dr.findElement(By.cssSelector(".entry-title a"));
System.out.println(first_post);
assertEquals(title,first_post.getText()); } @Test(expected=NoSuchElementException.class)
public void testDeletePost(){
System.out.println("delete test"); String username = "admin";
String passwd = "123456";
//登录
this.Login(username, passwd); //创建文章
String postId = this.createPost(); this.dr.get("http://localhost/wordpress/wp-admin/edit.php"); //计算文章id
String rowId = "post-"+postId;
WebElement row = this.dr.findElement(By.id(rowId)); //执行删除
Actions action = new Actions(this.dr);
action.moveToElement(row).perform();
row.findElement(By.cssSelector(".trash a")).click(); //assertFalse(this.isPostRowExists(rowId)); this.dr.findElement(By.id(rowId)); } @Test
public void TestView(){
System.out.println("view test");
String username = "admin";
String password = "123456";
this.Login(username, password); //创建文章
String title = "Test title" + System.currentTimeMillis();
String postId = this.createPost(title);
//String postId = this.createPost(); this.dr.get("http://localhost/wordpress/wp-admin/edit.php"); // 计算文章id
String rowId = "post-" + postId;
WebElement row = this.dr.findElement(By.id(rowId)); // 执行查询
Actions action = new Actions(this.dr);
action.moveToElement(row).perform();
row.findElement(By.cssSelector(".view a")).click(); //断言 //dr.get("http://localhost/wordpress/?p="+postId); System.out.println(dr.findElement(By.cssSelector(".entry-title")));
WebElement first_post = dr.findElement(By.cssSelector(".entry-title")); assertEquals(title,first_post.getText()); } @Test
public void TestRevisePost(){
System.out.println("revise test"); String username = "admin";
String passwd = "123456";
//登录
this.Login(username, passwd);
//创建
String postId = this.createPost(); dr.get("http://localhost/wordpress/wp-admin/edit.php");
//获取id
String rowId = "post-"+postId;
WebElement row = this.dr.findElement(By.id(rowId));
//执行修改
Actions action = new Actions(this.dr);
action.moveToElement(row).perform();
row.findElement(By.cssSelector(".edit a")).click(); //dr.get("http://localhost/wordpress/wp-admin/post.php?post="+postId+"&action=edit"); dr.findElement(By.name("post_title")).clear();
this.setContent(null);
String title = "Test title" + System.currentTimeMillis();
String content = "Test title" + System.currentTimeMillis();
dr.findElement(By.name("post_title")).sendKeys(title);
this.setContent(content);
dr.findElement(By.id("publish")).click();
//this.createPost(title); dr.get("http://localhost/wordpress/");
WebElement first_post = dr.findElement(By.cssSelector(".entry-title a"));
System.out.println(first_post);
assertEquals(title,first_post.getText()); } public void Login(String username,String password){
this.dr.get("http://localhost/wordpress/wp-login.php");
//输入用户名和密码,点击登录
dr.findElement(By.id("user_login")).sendKeys(username);
dr.findElement(By.id("user_pass")).sendKeys(password);
dr.findElement(By.id("wp-submit")).click();
} public void setContent(String content) { String js = "document.getElementById('content_ifr').contentWindow.document.body.innerHTML='"
+ content + "'";
((JavascriptExecutor) dr).executeScript(js);
} public String createPost(String title,String content){ this.dr.get("http://localhost/wordpress/wp-admin/post-new.php");
//String title = "Test title" + System.currentTimeMillis();
//this.dr.findElement(By.name("post_title")).clear();
this.dr.findElement(By.name("post_title")).sendKeys(title);
this.setContent(content);
dr.findElement(By.name("publish")).click();
return this.fetchPostId();
} public String fetchPostId(){
String postUrl = this.dr.findElement(By.id("sample-permalink")).getText();
String[] arr = postUrl.split("=");
return arr[1];
} public String createPost(){
String title = "Test title" + System.currentTimeMillis();
String content = "Test Content" + System.currentTimeMillis();
return this.createPost(title,content);
} public String createPost(String title){
String content = "test Content" + System.currentTimeMillis();
return this.createPost(title,content);
} /*public boolean isPostRowExists(String rowId){ try{
this.dr.findElement(By.cssSelector(rowId));
return true;
}catch(NoSuchElementException e){
return false;
}
}*/ }
查看文章思路


修改文章代码有点重复,暂时未重构
wordpress登录、修改、删除、查看代码记录的更多相关文章
- Git----02本地仓库进行文件添加&修改&删除&查看
一.将新文件上传到本地仓库----使用小乌龟工具 1.1.将文件添加到暂存区 进入仓库目录,创建文件,添加暂存区 1.2.将文件添加到本地仓库 选中已经添加到暂存区的文件,进行提交 二.查看本 ...
- linux下添加删除,修改,查看用户和用户组
一.组操作 1.创建组: groupadd test #增加一个test组 2.修改组 groupmod -n test2 test #将test组的名子改成test2 3.删除组 groupdel ...
- linux下添加,删除,修改,查看用户和用户组
标签:gpasswd, groupadd, groupdel, groupmod, linux, useradd, userdel, usermod, who 一,组操作 1,创建组 groupadd ...
- python3之对本地TXT文件进行增加,删除,修改,查看功能。
由于是初学,代码如有不足,欢迎指出! 本博客记录我的编程之路,记录所学到的知识,分享所学心得! 这是我的一个作业. 首先分析要求: 创建一个TXT文件用于存储账号与密码 实现对文件进行增加,删除,修改 ...
- 使用oracle数据库,多用户同时对一个表进行增加,删除,修改,查看等操作,会不会有影响?
使用oracle数据库,多用户同时对一个表进行增加,删除,修改,查看等操作,会不会有影响? 1.问题:各操作间或者性能上会不会有影响? 如果有该如何解决? 多用户操作的影响主要是回锁定记录,oracl ...
- Windows Server查看和记录远程登录信息的方法
前两天我的一台Windows Server 2012R2的服务器中了传说中的cryptowall病毒,所有数据文件都被加密,需要我支付1个比特币才能解码.幸好服务器上没什么重要的文件,还好我没钱,我选 ...
- 1) 上传多张图片时 ,对 $_FILES 的处理. upload ; 2)fileinput 上传多张图片. 3) 修改,删除的时候删除原来的资源,图片 update, delete , 删除 4)生成器中两个字段上传图片的时候,要修改生成器生成的代码
1上传多张图片, 要对 $_FILES进行 重新处理. //添加 public function addCourseAlbumAction() { $CourseAlbumModel = new Co ...
- 学习Git的一点心得以及如何把本地修改、删除的代码上传到github中
一:学习Github的资料如下:https://git.oschina.net/progit/ 这是一个学习Git的中文网站,如果诸位能够静下心来阅读,不要求阅读太多,只需要阅读前三章,就可以掌握Gi ...
- git log 查看提交记录,参数:
git log 查看提交记录,参数:-n (n是一个正整数),查看最近n次的提交信息 $ git log -2 查看最近2次的提交历史记录 -- fileName fileName为任意文件名,查看指 ...
随机推荐
- HTML5原生拖拽/拖放⎡Drag & Drop⎦详解
前言 拖放(drap && drop)在我们平时的工作中,经常遇到.它表示:抓取对象以后拖放到另一个位置.目前,它是HTML5标准的一部分.我从几个方面学习并实践这个功能. 拖放的流程 ...
- enote笔记法(2)——why的使用
章节:why的使用 用法: why 概念|词汇(比概念更一般的形式的keyword)|短语|句子 用法1: why 概念|why keyword([比概念更一般的形式的keyword]) “why 概 ...
- Python 运行效率为何低
当我们提到一门编程语言的效率时:通常有两层意思,第一是开发效率,这是对程序员而言,完成编码所需要的时间:另一个是运行效率,这是对计算机而言,完成计算任务所需要的时间.编码效率和运行效率往往是鱼与熊掌的 ...
- 自己动手写Redis客户端(C#实现)4 - 整数回复
整数回复 整数回复就是一个以 ":" 开头, CRLF 结尾的字符串表示的整数. 比如说, ":0\r\n" 和 ":1000\r\n" 都 ...
- 你绝不能错过的效率神器 —— Alfred
文章首发于[博客园-陈树义],点击跳转到原文<你绝不能错过的效率神器 -- Alfred> Alfred 是 Mac 系统上一款专注于效率提升的著名应用,它能帮你快速打开网页.快速进行自定 ...
- Java数据结构和算法(四)——栈
前面我们讲解了数组,数组更多的是用来进行数据的存储,纯粹用来存储数据的数据结构,我们期望的是插入.删除和查找性能都比较好.对于无序数组,插入快,但是删除和查找都很慢,为了解决这些问题,后面我们会讲解比 ...
- [LeetCode] N皇后问题
LeetCode上面关于N皇后有两道题目:51 N-Queens:https://leetcode.com/problems/n-queens/description/ 52 N-Queens II: ...
- 解决阿里云服务器3306端口无法访问的问题(windows server 2008r2)
3306端口一般是指mysql数据的默认端口.郁闷了几天的问题,远程无法连接服务器上的mysql服务.今天终于得到彻底解决. 首先,你要确保在服务器上安装好Mysql,并能本地启动.修改密码(如不知道 ...
- RGBA 和 opacity的区别
两者都可以设置透明度 区别 RGBA 只影响当前元素 opacity 后代会继承该css 值,暂时还没有办法清除该css 在线演示
- 蓝桥杯第七届C/C++B省赛凑算式
第三题: 凑算式 B DEF A + --- + ------- = 10 C GHI (如果显示有问题,可以参见[图1.jpg]) 这个算式中A~I代表1~9的数字, ...