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为任意文件名,查看指 ...
随机推荐
- 《Linux命令行与shell脚本编程大全》第十二章 使用结构化命令
许多程序要就对shell脚本中的命令施加一些逻辑控制流程. 结构化命令允许你改变程序执行的顺序.不一定是依次进行的 12.1 使用if-then语句 如下格式: if command then ...
- 系统学习DOM事件机制
本文将从以下几个方面介绍DOM事件: 基本概念:DOM事件的级别 DOM事件模型,事件流 描述DOM事件捕获的具体流程 Event对象的常见应用 自定义事件 DOM事件的级别 //DOM0 eleme ...
- SpringCloud接入EDAS——服务发现篇
旁白 很久没有写技术文章了,最近不是写水文就是写小说.说到底,还是最近很少研究技术的缘故,已经到了江郎才尽的地步了. 不过,LZ无意间看到自己团队的小伙伴写的一些文章,觉得还是不错的,于是便动了心思, ...
- 提高运维效率(二)桌面显示IP
运维人员远控电脑询问IP时,总要告诉用户找ip的步骤,岂不很烦? 以下方法直观地把ip地址显示在桌面上,再做个入职培训,即可提高运维效率. 1. 下载bginfo.exe软件,放到域控下的netlo ...
- 最耗性能的SQL语句
设计优化–常见杀手级SQL •SELECT * vsSELECT col1, col2 •ORDER BY RAND() •LIMIT huge_num, offset •SELECT COUNT(* ...
- Python数据分析中 DataFrame axis=0(0轴)与axis=1(1轴)的理解
python中的axis究竟是如何定义的呢?他们究竟代表是DataFrame的行还是列? 直接上代码people=DataFrame(np.random.randn(5,5), columns=['a ...
- 随机生成N个字符(包含数字和字母)
'************************************************************* ' Name: GetRandomString ' Purpose: 随机 ...
- git log 中文乱码问题(浪费了一天)
git log和gitcommit中文出现乱码,花了大半天的时间试了网上的各种方法,还是搞不定. 只好放大招. 卸载软件后重装,还没有进行任何配置,git config --list 发现有大量的配置 ...
- php接入支付宝的流程
php接入支付宝的流程写在这里供像我一样的小白参考. 1.首先要有一个创建一个应用(选好自己想要的功能,关于支付的功能,貌似都需要签约) 2.下载SDK&Dome(网址https://doc. ...
- ThinkPHP5.0 实现 app支付宝支付功能
前几天做项目,要求要用到支付宝接口,第一次做,弄了好几天 各种坑啊,简单写一下我做支付宝支付的过程,希望对也是第一次做支付宝支付的童鞋有帮助, 不懂的可以先去支付平台看一下支付宝支付的文档,我是下的d ...