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为任意文件名,查看指 ...
随机推荐
- 【Java框架型项目从入门到装逼】第二节 - Spring框架 AOP的丧心病狂解说,你喜欢露娜的月下无限连吗?
继续上一节的内容,多几个jar包: aop技术是面向切面编程思想,作为OOP的延续思想添加到企业开发中,用于弥补OOP开发过程中的缺陷而提出的编程思想.AOP底层也是面向对象:只不过面向的不是普通的O ...
- Maven启动Java Web工程,8081和8086端口号被占用
Maven启动Java Web工程, <!-- 配置tomcat插件 --> <build> <plugins> <plugin> <groupI ...
- canvas三环加载进度条
之前做了一个三个圆形叠加在一起的加载,用的是定位和cile来操作,但是加载的头部不能是圆形.后来用canvas做了一个,但是这个加载的进度不好调整,原理很简单,就是让一个圆,按照圆形轨迹进行运动就可以 ...
- Zabbix 3.0 从入门到精通(zabbix使用详解)
第1章 zabbix监控 1.1 为什么要监控 在需要的时刻,提前提醒我们服务器出问题了 当出问题之后,可以找到问题的根源 网站/服务器 的可用性 1.1.1 网站可用性 在软件系统的高可靠性(也 ...
- 逻辑回归,附tensorflow实现
本文旨在通过二元分类问题.多元分类问题介绍逻辑回归算法,并实现一个简单的数字分类程序 在生活中,我们经常会碰到这样的问题: 根据苹果表皮颜色判断是青苹果还是红苹果 根据体温判断是否发烧 这种答案只有两 ...
- iis7 部署网站 403错误
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i 403 - 禁止访问: 访问被拒绝. 您无权使用所提供的凭据查看此 ...
- 常用接口简析3---IList和List的解析
常用接口的解析(链接) 1.IEnumerable深入解析 2.IEnumerable.IEnumerator接口解析 3.IComparable.IComparable接口解析 学习第一步,先上菜: ...
- C#对SQLite、Access数据库操作的封装,很好用的~
1.对SQLite的封装: using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- 使用ThinkPHP的扩展功能
文件上传类的代码位于“\ThinkPHP\Libabry\Think\Uplod.class.php”,实例化电偶用即可.1:在Home模块Index控制器test方法中实现文件上传功能.打开文件\A ...
- Python中的列表生成器,迭代器的理解
首先,思考一个问题,比如,我们想生成0-100的列表,我们怎么做? 当然,可以写成 list1=[1,2,3...,100] 可以看出,这种方法不适合生成长的列表,那么Python中就可以利用已有的列 ...