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. VueJS使用笔记

    html: <script src='vue.js'></script> <div id='app'> <span>{{msg}}</span&g ...

  2. 关于如何获取移动端 touchmove 事件中真正触摸点下方的元素

    移动端的touchstart, touchmove, touchend三个事件,点击元素并拖动时,获取到了touchmove事件, 但是event.touches[0].target所指向的元素却是t ...

  3. python学习笔记 list

    1.list中的任一元素可以是任一类型.可以是混合的,如,前两个字符串后面的是数字.都是可以的. 2.可以用-1表示最后一个元素. 3.注意不要越界. 4.len(mates) 用来计算list的大小 ...

  4. javac 实现原理

    javac 概述 javac 是jdk bin目录下的一个脚本. 用于编译 java程序的源代码,但是 其实现的本质 是基于 jdk 标准类库中的 javac类库实现,所以java的编译器实质上是一个 ...

  5. Spring框架——IOC依赖注入

    本来想把IOC和AOP一起介绍的,但是AOP内容太多了,所以就分开了,最后的结果就是这一篇只剩下一点点了.这不是第一次写关于IOC的文章了,之前写过Java反射,Java注解,也写过通过XML解析实现 ...

  6. MVC Code First(数据模型实例讲解)

    首先配置好web.config <connectionStrings> <add name="BookDbContext" connectionString=&q ...

  7. 4.2 例题: 统计字符数 poj2247

    问题描述 判断一个由 a-z 这 26 个字符组成的字符串中哪个字符出现的次数最多 输入:第 1 行是测试数据的组数 n,每组测试数据占 1 行,是一个由 a-z 这 26 个字符组 成的字符串,每组 ...

  8. JS的数据类型及转换(还是基础的东西)

    朋友说我这是再自娱自乐,我只想说,你说的对

  9. 随笔-SQL的三种存储引擎即三种类型的表

    MYSQL 的环境变量:......server/bin下 引擎(Engine):是电子平台上开发程序或系统的核心组件.利用引擎,开发者可迅速建立.铺设程序所需的功能,或利用其辅助程序的运转.一般而言 ...

  10. django事务处理

    #导包 from django.db import transaction try: #django默认是自动提交到数据库,此处设置不让其自动提交 transaction.set_autocommit ...