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登录、修改、删除、查看代码记录的更多相关文章

  1. Git----02本地仓库进行文件添加&修改&删除&查看

    一.将新文件上传到本地仓库----使用小乌龟工具 1.1.将文件添加到暂存区 进入仓库目录,创建文件,添加暂存区     1.2.将文件添加到本地仓库 选中已经添加到暂存区的文件,进行提交 二.查看本 ...

  2. linux下添加删除,修改,查看用户和用户组

    一.组操作 1.创建组: groupadd test #增加一个test组 2.修改组 groupmod -n test2 test #将test组的名子改成test2 3.删除组 groupdel ...

  3. linux下添加,删除,修改,查看用户和用户组

    标签:gpasswd, groupadd, groupdel, groupmod, linux, useradd, userdel, usermod, who 一,组操作 1,创建组 groupadd ...

  4. python3之对本地TXT文件进行增加,删除,修改,查看功能。

    由于是初学,代码如有不足,欢迎指出! 本博客记录我的编程之路,记录所学到的知识,分享所学心得! 这是我的一个作业. 首先分析要求: 创建一个TXT文件用于存储账号与密码 实现对文件进行增加,删除,修改 ...

  5. 使用oracle数据库,多用户同时对一个表进行增加,删除,修改,查看等操作,会不会有影响?

    使用oracle数据库,多用户同时对一个表进行增加,删除,修改,查看等操作,会不会有影响? 1.问题:各操作间或者性能上会不会有影响? 如果有该如何解决? 多用户操作的影响主要是回锁定记录,oracl ...

  6. Windows Server查看和记录远程登录信息的方法

    前两天我的一台Windows Server 2012R2的服务器中了传说中的cryptowall病毒,所有数据文件都被加密,需要我支付1个比特币才能解码.幸好服务器上没什么重要的文件,还好我没钱,我选 ...

  7. 1) 上传多张图片时 ,对 $_FILES 的处理. upload ; 2)fileinput 上传多张图片. 3) 修改,删除的时候删除原来的资源,图片 update, delete , 删除 4)生成器中两个字段上传图片的时候,要修改生成器生成的代码

    1上传多张图片, 要对 $_FILES进行 重新处理. //添加 public function addCourseAlbumAction() { $CourseAlbumModel = new Co ...

  8. 学习Git的一点心得以及如何把本地修改、删除的代码上传到github中

    一:学习Github的资料如下:https://git.oschina.net/progit/ 这是一个学习Git的中文网站,如果诸位能够静下心来阅读,不要求阅读太多,只需要阅读前三章,就可以掌握Gi ...

  9. git log 查看提交记录,参数:

    git log 查看提交记录,参数:-n (n是一个正整数),查看最近n次的提交信息 $ git log -2 查看最近2次的提交历史记录 -- fileName fileName为任意文件名,查看指 ...

随机推荐

  1. SQL 数据操作(实验六)

    SQL 数据操作 emp.dept 目标表结构及数据 INSERT 命令的使用与结果验证 2.1把一名新来雇员信息插入到EMP表中:雇员号:1011 姓名: 王晓明 入职日期:今天 ```insert ...

  2. js 图片转换为base64

    <input id="file" type="file"> <img id="img" style="max-h ...

  3. spring boot 中 Mybatis plus 多数据源的配置方法

    最近在学习spring boot,发现在jar包依赖方面做很少的工作量就可以了,对于数据库操作,我用的比较多的是mybatis plus,在中央仓库已经有mybatis-plus的插件了,对于单数据源 ...

  4. JavaScript学习笔记(十三)——生成器(generator)

    在学习廖雪峰前辈的JavaScript教程中,遇到了一些需要注意的点,因此作为学习笔记列出来,提醒自己注意! 如果大家有需要,欢迎访问前辈的博客https://www.liaoxuefeng.com/ ...

  5. C/C++中如何接收return返回来的数组元素

    我们知道return语句作为被调用函数的结束,返回给调用者函数值.一般来说,是返回一个函数值,像一个int, double,char等类型的数据,当然也可以是他们的指针.但是当我们遇到要返回很多数怎么 ...

  6. Nomad入门

    Nomad 简介 Nomad是一个管理机器集群并在集群上运行应用程序的工具. Nomad的特点: 支持docker,Nomad的job可以使用docker驱动将应用部署到集群中. Nomad安装在li ...

  7. Mybatis(二)参数(Parameters)传递

    Mybatis参数(Parameters)传递  1..单个参数 可以接受基本类型,对象类型,集合类型的值.这种情况MyBatis可直接使用这个参数,不需要经过任何处理. <!-- 根据id查询 ...

  8. java连接VMware虚拟机Oracle数据库问题

    最近在电脑上装了虚拟机,为的是在虚拟机上安装Oracle数据库,Oracle实在太占内存,配置低的电脑装个Oracle几乎就瘫了,没办法,搞个虚拟机玩玩.我虚拟机用的是xp系统,顺便怀念下经典.装好O ...

  9. 51Nod--1011最大公约数GCD

    1011 最大公约数GCD 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 输入2个正整数A,B,求A与B的最大公约数. Input 2个数A,B,中间用 ...

  10. Linux Redis集群搭建与集群客户端实现

    硬件环境 本文适用的硬件环境如下 Linux版本:CentOS release 6.7 (Final) Redis版本: Redis已经成功安装,安装路径为/home/idata/yangfan/lo ...