admin test

This commit is contained in:
licy@guangda.work 2023-04-21 17:46:18 +08:00 committed by Edward Yang
parent 52fbd72915
commit e33521f60e
19 changed files with 475 additions and 24 deletions

View File

@ -37,6 +37,10 @@ use PHPUnit\TextUI\DefaultResultPrinter;
$suite->addTestFile('.\tests\Browser\dusktest\page\admin\AddCusGroupTest.php');//添加用户组
$suite->addTestFile('.\tests\Browser\dusktest\page\admin\EditCusGroupTest.php');//编辑用户组
$suite->addTestFile('.\tests\Browser\dusktest\page\admin\DelCusGroupTest.php');//删除用户组
$suite->addTestFile('.\tests\Browser\dusktest\page\admin\CusEmptyRecycleTest.php');//清空回收站
$suite->addTestFile('.\tests\Browser\dusktest\page\admin\CustomerRecycleTest.php');//恢复客户信息
$suite->addTestFile('.\tests\Browser\dusktest\page\admin\DelCusRecycleTest.php');//从回收站删除客户信息
$suite->addTestFile('.\tests\Browser\dusktest\page\admin\AddExpressTest.php');//添加快递公司
//前后台联测

View File

@ -2,10 +2,17 @@
const admin_top = [
"login_url" =>"/admin",
"root"=> "root",
"mg_index"=>".navbar.navbar-left li:nth-child(1)",//管理首页
"mg_order"=>".navbar.navbar-left li:nth-child(2)",//管理首页
"mg_product"=>".navbar.navbar-left li:nth-child(3)",//管理首页
"mg_customers"=>".navbar.navbar-left li:nth-child(4)",//管理首页
"mg_article"=>".navbar.navbar-left li:nth-child(5)",//管理首页
"system_set"=>".navbar.navbar-left li:nth-child(6)",//管理首页
'go_catalog'=>'访问前台',
"sign_out"=> " 退出登录",
"mg_product"=>"商品管理",
"mg_customers"=>"客户管理",
"sign_out"=> "退出登录",
// "mg_order"=> "订单管理",
// "mg_product"=>"商品管理",
// "mg_customers"=>"客户管理",
"VIP"=>"VIP",
"plugins_market"=>"插件市场",
"sw_language"=>"简体中文",

View File

@ -52,7 +52,15 @@ const cre_cus_group = [
"discount"=>"#customer-app > div.el-dialog__wrapper > div > div.el-dialog__body > form > div:nth-child(3) > div > div > input",
"save_btn"=>"#customer-app > div.el-dialog__wrapper > div > div.el-dialog__body > form > div:nth-child(4) > div > div > button.el-button.el-button--primary",
];
const customer_assert = [
const empty_recycle = [
"empty_btn"=>"#customer-app > div.card-body > div.d-flex.justify-content-between.mb-4 > button",//清空数据按钮
"recycle_btn"=>"#customer-app > div.card-body > div.table-push > table > tbody > tr > td:nth-child(8) > a",//恢复按钮
"recycle_del"=>"#customer-app > div.card-body > div.table-push > table > tbody > tr > td:nth-child(8) > button",//删除按钮
//获取即将被删除的客户email
"customer_text"=>"#customer-app > div.card-body > div.table-push > table > tbody > tr > td:nth-child(2)",
"sure_btn"=>"确定",
"assert_text"=>"暂无数据~",
];

View File

@ -0,0 +1,9 @@
<?php
const express = [
"express_company"=>"顺风快递",
"express_code"=>"11011",
];

View File

@ -0,0 +1,24 @@
<?php
const order_right = [
"url"=>"/admin/orders",
"search_order" =>"#app > form > div:nth-child(1) > div:nth-child(1) > div > div > input",//搜索栏--订单号
"search_bth"=>"#app > div > div > button:nth-child(1)",//搜索按钮
"view_btn"=>"#customer-app > div > div.table-push > table > tbody > tr > td:nth-child(9) > a",//查看按钮
];
const order_details = [//订单详情页
"pull_btn"=>"#app > form > div.el-form-item.is-required > div > div > div > span > span > i",//状态栏下拉按钮
// "paid"=>".el-select-dropdown__item",//已支付
"paid"=>".el-scrollbar__view.el-select-dropdown__list li:nth-child(1)",//已支付
"cancel"=>".el-scrollbar__view.el-select-dropdown__list li:nth-child(2)",//已取消
"alter_btn"=>"#app > form > div:nth-child(5) > div > button > span",
"Shipped"=>".el-scrollbar__view.el-select-dropdown__list li:nth-of-type(2)",//已发货
"express_btn"=>"#app > form > div:nth-child(3) > div > div > div > span > span > i",//快递下拉按钮
//
"express_1"=>".el-scrollbar__view.el-select-dropdown__list:nth-of-type(2) > ul > li:nth-child(1)",//选择第一个快递
"order_number"=>"#app > form > div:nth-child(4) > div > div > input",//订单号
"submit"=>"#app > form > div:nth-child(7) > div > button",//提交按钮
""=>"",
];

View File

@ -0,0 +1,22 @@
<?php
const system_set = [
"basic_set"=>".nav.nav-tabs.nav-bordered.mb-5 li:nth-child(1)",//基础设置
"store_set"=>".nav.nav-tabs.nav-bordered.mb-5 li:nth-child(2)",//商店设置
"pay_set"=>".nav.nav-tabs.nav-bordered.mb-5 li:nth-child(3)",//结账设置
"images_set"=>".nav.nav-tabs.nav-bordered.mb-5 li:nth-child(4)",//图片设置
"express_set"=>".nav.nav-tabs.nav-bordered.mb-5 li:nth-child(5)",//快递公司
"advanced_filter"=>".nav.nav-tabs.nav-bordered.mb-5 li:nth-child(6)",//高级筛选
"email_set"=>".nav.nav-tabs.nav-bordered.mb-5 li:nth-child(7)",//邮件设置
];
const express_set = [ //快递公司
"add_btn"=>".bi.bi-plus-circle.cursor-pointer.fs-4",//加号
"express_company"=>'input[name="express_company[0][name]"]',//公司名字
"express_code"=>'input[name="express_company[0][code]"]',//code
"save_btn"=>"#content > div.page-title-box.py-1.d-flex.align-items-center.justify-content-between > div > button",
];
const express_assert = [ //断言信息
"assert_ful"=>"更新成功!",
];

View File

@ -2,6 +2,12 @@
const checkout = [
'submit' => 'Submit Order',
'submit' => 'Submit Order',//提交按钮
//订单成功验证信息
'assert' => 'Congratulations, the order was successfully generated!',
//订单号
'order_num'=>'.fw-bold',
'view_order'=>'View Order ',
///
];

View File

@ -5,9 +5,11 @@ const index = [
"buy_btn" => "#product-top > div:nth-child(2) > div > div.quantity-btns > button.btn.btn-dark.ms-3.fw-bold",//购买按钮
"address_btn" => "#checkout-address-app > div.checkout-black > div.addresses-wrap > div > div > div > button", //添加地址
"login_text" => "Home",
"right_icon"=>".navbar-nav flex-row",
];
const index_top = [
"wishlist_btn" => "",//购买商品图标
// "wishlist_btn" => "",//收藏商品图标
"wishlist_btn" => ".navbar-nav.flex-row li:nth-child(2)",//收藏商品图标
"top_Sports"=>"Sports",
"buy_btn" => "#product-top > div:nth-child(2) > div > div.quantity-btns > button.btn.btn-dark.ms-3.fw-bold",//购买按钮
"address_btn" => "#checkout-address-app > div.checkout-black > div.addresses-wrap > div > div > div > button", //添加地址
@ -17,10 +19,19 @@ const index_top = [
];
const index_cart = [
"cart_product_text" => "#offcanvas-right-cart > div.offcanvas-body.pt-0 > div > div > div.product-info.d-flex.align-items-center > div.right.flex-grow-1 > a",
"cart_icon"=>"",
"cart_icon"=>"",//购物车图标
// "cart_icon"=>".navbar-nav.flex-row li:nth-child(4)",//购物车图标
"product_text"=>"#offcanvas-right-cart > div.offcanvas-body.pt-0 > div > div > div.product-info.d-flex.align-items-center > div.right.flex-grow-1 > a",//购物车内商品名字
"Delete_btn" => "#offcanvas-right-cart > div.offcanvas-body.pt-0 > div > div > div.product-info.d-flex.align-items-center > div.right.flex-grow-1 > div.product-bottom.d-flex.justify-content-between.align-items-center > span", //删除按钮
"product_num"=>"#offcanvas-right-cart > div.offcanvas-footer > div.d-flex.justify-content-between.align-items-center.mb-2.p-3.bg-light.top-footer > div:nth-child(2) > strong:nth-child(2) > span",
"cart_Checkout"=>"#offcanvas-right-cart > div.offcanvas-footer > div.p-4 > a.btn.w-100.fw-bold.btn-dark.to-checkout",
];
const index_login = [
"login_icon"=>".navbar-nav.flex-row li:nth-child(3)",//购物车图标
"product_text"=>"#offcanvas-right-cart > div.offcanvas-body.pt-0 > div > div > div.product-info.d-flex.align-items-center > div.right.flex-grow-1 > a",//购物车内商品名字
"Delete_btn" => "#offcanvas-right-cart > div.offcanvas-body.pt-0 > div > div > div.product-info.d-flex.align-items-center > div.right.flex-grow-1 > div.product-bottom.d-flex.justify-content-between.align-items-center > span", //删除按钮
"product_num"=>"#offcanvas-right-cart > div.offcanvas-footer > div.d-flex.justify-content-between.align-items-center.mb-2.p-3.bg-light.top-footer > div:nth-child(2) > strong:nth-child(2) > span",
"cart_Checkout"=>"#offcanvas-right-cart > div.offcanvas-footer > div.p-4 > a.btn.w-100.fw-bold.btn-dark.to-checkout",
];

View File

@ -8,10 +8,9 @@ const order = [
"address_btn"=>"#checkout-address-app > div.checkout-black > div.addresses-wrap > div > div > div > button", //添加地址
"login_text"=> "Home",
];
//const register = [
// "register_email" => "#page-login > div.login-wrap > div:nth-child(3) > div.card-body.px-md-2 > form > div:nth-child(1) > div > div > input",
// "register_pwd"=> "#page-login > div.login-wrap > div:nth-child(3) > div.card-body.px-md-2 > form > div:nth-child(2) > div > div > input",
// "register_re_pwd"=> "#page-login > div.login-wrap > div:nth-child(3) > div.card-body.px-md-2 > form > div:nth-child(3) > div > div > input",
// "register_btn"=> "Register",
// "register_text"=> "Home",
//];
const ca_order_status = [
"Unpaid"=>"Unpaid",//待支付
"paid"=>"paid",//已支付
"Shipped"=>"Shipped",//已发货
"Completed"=>"Completed",
];

View File

@ -0,0 +1,51 @@
<?php
namespace Tests\Browser;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
require_once(dirname(__FILE__) . '/../../data/admin/login.php');
require_once(dirname(__FILE__) . '/../../data/admin/login_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/admin_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/systemset_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/customer_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/express.php');
class AddExpressTest extends DuskTestCase
{
/**
* A basic browser test example.
* @return void
*/
public function testExpressTest()
{
$this->browse(function (Browser $browser)
{
$browser->visit(admin_login['login_url'])
//1.登录
->type(admin_login['login_email'], admin_true_login['email'])
->type(admin_login['login_pwd'], admin_true_login['password'])
->press(admin_login['login_btn'])
->pause(2000)
//2.点击系统设置
->click(admin_top['system_set'])
//3.点击邮件设置
->click(system_set['express_set'])
->pause(2000)
//点击+号
->click(express_set['add_btn'])
//填写快递信息
->type(express_set['express_company'], express['express_company'])
->type(express_set['express_code'], express['express_code'])
->press(express_set['save_btn'])
->pause(5000)
->assertSee(express_assert['assert_ful'])
->pause(3000)
;
});
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace Tests\Browser;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
require_once(dirname(__FILE__) . '/../../data/admin/login.php');
require_once(dirname(__FILE__) . '/../../data/admin/login_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/admin_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/customer_page.php');
class CusEmptyRecycleTest extends DuskTestCase
{
/**
* A basic browser test example.
* @return void
*/
//场景1 email不合法
public function testEmptyRecycle()
{
$this->browse(function (Browser $browser)
{
$browser->visit(admin_login['login_url'])
//1.登录
->type(admin_login['login_email'], admin_true_login['email'])
->type(admin_login['login_pwd'], admin_true_login['password'])
->press(admin_login['login_btn'])
->pause(2000)
->clickLink(admin_top['mg_customers'])
//2.点击回收站
->clickLink(customer_left['re_station'])
//3.点击清空回收站
->press(empty_recycle['empty_btn'])
->pause(2000)
->press(empty_recycle['sure_btn'])
->pause(2000)
->assertSee(empty_recycle['assert_text'])
;
});
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace Tests\Browser;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
require_once(dirname(__FILE__) . '/../../data/admin/login.php');
require_once(dirname(__FILE__) . '/../../data/admin/login_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/admin_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/customer_page.php');
class CustomerRecycleTest extends DuskTestCase
{
/**
* A basic browser test example.
* @return void
*/
//场景1 email不合法
public function testEmptyRecycle()
{
$this->browse(function (Browser $browser)
{
$browser->visit(admin_login['login_url'])
//1.登录
->type(admin_login['login_email'], admin_true_login['email'])
->type(admin_login['login_pwd'], admin_true_login['password'])
->press(admin_login['login_btn'])
->pause(2000)
->clickLink(admin_top['mg_customers'])
//2.点击回收站
->clickLink(customer_left['re_station']);
$customer_text=$browser->text(empty_recycle['customer_text']);
echo $customer_text;
//3.点击恢复按钮
$browser->press(empty_recycle['recycle_btn'])
->pause(2000)
//4.点击客户列表
->clickLink(customer_left['customer_list'])
//验证客户信息是否存在于页面
->assertSee($customer_text)
;
});
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace Tests\Browser;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
require_once(dirname(__FILE__) . '/../../data/admin/login.php');
require_once(dirname(__FILE__) . '/../../data/admin/login_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/admin_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/customer_page.php');
class DelCusRecycleTest extends DuskTestCase
{
/**
* A basic browser test example.
* @return void
*/
//场景1 email不合法
public function testDelCusRecycle()
{
$this->browse(function (Browser $browser)
{
$browser->visit(admin_login['login_url'])
//1.登录
->type(admin_login['login_email'], admin_true_login['email'])
->type(admin_login['login_pwd'], admin_true_login['password'])
->press(admin_login['login_btn'])
->pause(2000)
->clickLink(admin_top['mg_customers'])
//先删除一个客户
->press(customer_list['del_customer'])
->press(customer_list['sure_btn'])
->pause(1000)
//2.点击回收站
->clickLink(customer_left['re_station']);
$customer_text=$browser->text(empty_recycle['customer_text']);
echo $customer_text;
//3.点击删除按钮
$browser->press(empty_recycle['recycle_del'])
->pause(2000)
->press(empty_recycle['sure_btn'])
//验证客户信息是否存在于页面
->assertSee($customer_text)
->pause(5000)
;
});
}
}

View File

@ -31,11 +31,10 @@ class GoCatalogTest extends DuskTestCase
->press(admin_login['login_btn'])
->pause(2000)
//2.去往前台
->clickLink(admin_top['root'])
->pause(2000)
->clicklink(admin_top['root'])
->pause(3000)
->clickLink(admin_top['go_catalog'])
->pause(2000)
//3.切换到第二个窗口并断言
->driver->switchTo()->window($browser->driver->getWindowHandles()[1]);
$browser->assertPathIs(index['login_url'])
;

View File

@ -0,0 +1,61 @@
<?php
namespace Tests\Browser;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
require_once(dirname(__FILE__) . '/../../data/admin/login.php');
require_once(dirname(__FILE__) . '/../../data/admin/login_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/admin_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/cus_grounp.php');
require_once(dirname(__FILE__) . '/../../data/admin/customer_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/systemset_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/order_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/express.php');
class Test extends DuskTestCase
{
/**
* A basic browser test example.
* @return void
*/
public function testAddCusGroup()
{
$this->browse(function (Browser $browser)
{
$browser->visit(admin_login['login_url'])
//登录后台
->type(admin_login['login_email'], admin_true_login['email'])
->type(admin_login['login_pwd'], admin_true_login['password'])
->press(admin_login['login_btn'])
->pause(2000)
//去往前台
->pause(3000)
->click(admin_top['mg_order'])
//点击查看按钮
->press(order_right['view_btn'])
//点击状态栏下拉按钮
->pause(2000)
->press(order_details['pull_btn'])
//修改状态为已支付
->pause(2000)
->click(order_details['Shipped'])
->press(order_details['express_btn'])
//修改状态为已支付
->pause(5000)
->waitFor(order_details['express_1'])
->click(order_details['express_1'])
->type(order_details['order_number'], express['password'])
->press(order_details['submit'])
->pause(3000)
;
;
});
}
}

View File

@ -0,0 +1,102 @@
<?php
namespace Tests\Browser;
namespace App\Http\Controllers;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
use App\Http\Controllers\By;
require_once(dirname(__FILE__) . '/../../data/catalog/login.php');
require_once(dirname(__FILE__) . '/../../data/catalog/login_page.php');
require_once(dirname(__FILE__) . '/../../data/catalog/account_page.php');
require_once(dirname(__FILE__) . '/../../data/catalog/product_1.php');
require_once(dirname(__FILE__) . '/../../data/catalog/index_page.php');
require_once(dirname(__FILE__) . '/../../data/catalog/checkout_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/login.php');
require_once(dirname(__FILE__) . '/../../data/admin/login_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/order_page.php');
require_once(dirname(__FILE__) . '/../../data/admin/admin_page.php');
//已注册客户且有地址,直接购买商品
class AlterOrderStationTest extends DuskTestCase
{
public function testAlterOrderStation()
{
$this->browse(function (Browser $browser)
{
$browser->visit(admin_login['login_url'])
//登录后台
->type(admin_login['login_email'], admin_true_login['email'])
->type(admin_login['login_pwd'], admin_true_login['password'])
->press(admin_login['login_btn'])
->pause(2000)
//去往前台
->clicklink(admin_top['root'])
->pause(3000)
->clickLink(admin_top['go_catalog'])
->pause(2000)
//切换到前台下单
->driver->switchTo()->window($browser->driver->getWindowHandles()[1]);
//前台用户登录
//点击登录图标
$browser->click(index_login['login_icon'])
->type(login['login_email'], true_login['email'])
->type(login['login_pwd'], true_login['password'])
->press(login['login_btn'])
->pause(5000)
->clickLink(account['go_index'])
//3.向下滑动页面直到找到商品
->pause(2000)
->scrollIntoView(index['product_img'])
->pause(2000)
//点击要购买的商品
->press(index['product_img'])
//4.点击购买按钮
->press(product['product_1'])
->pause(5000)
//5.点击确认按钮
->press(checkout['submit'])
->pause(5000);
$elements = $browser->elements(checkout['order_num']);
$order_num =$elements[15]->getText();
//打印订单号
echo $order_num;
$browser->clickLink(checkout['view_order'])
//进入后台
->driver->switchTo()->window($browser->driver->getWindowHandles()[0]);
//点击订单管理按钮
$browser->clickLink(admin_top['mg_order'])
//搜索框输入订单号
->type(order_right['search_order'],$order_num)
//点击搜索按钮
->press(order_right['search_bth'])
->assertSee($order_num)
//点击查看按钮
->press(order_right['view_btn'])
//点击状态栏下拉按钮
->pause(2000)
->press(order_details['pull_btn'])
//修改状态为已支付
->pause(2000)
->click(order_details['paid'])
->press(order_details['alter_btn'])
->pause(3000)
//切换到前台
->driver->switchTo()->window($browser->driver->getWindowHandles()[1]);
$browser->pause(3000)
->refresh()
->pause(5000)
// 查看是否已支付
->assertSee(ca_order_status['paid'])
//
->click(admin_top['system_set'])
;
});
}
}

View File

@ -26,7 +26,7 @@ class AddCartTest extends DuskTestCase
->type(login['login_email'], true_login['email'])
->type(login['login_pwd'], true_login['password'])
->press(login['login_btn'])
->pause(2000)
->pause(5000)
//2.点击home跳转到首页
->clickLink(account['go_index'])
//3.向下滑动页面直到找到元素
@ -47,7 +47,7 @@ class AddCartTest extends DuskTestCase
->press(product['add_cart'])
->pause(3000)
//6.点击购物车按钮
->clickLink(index_cart['cart_icon'])
->click(index_cart['cart_icon'])
->pause(10000);
//6.断言购物车内商品是否与先前商品相同
$browser->assertSeeIn(index_cart['product_text'],$product_description)

View File

@ -43,7 +43,7 @@ class WishlistTest extends DuskTestCase
->press(product['Wishlist_icon'])
->pause(3000)
//6.点击顶部收藏认按钮
->clickLink(index_top['wishlist_btn'])
->click(index_top['wishlist_btn'])
->pause(1000)
//7.点击查看详情按钮
->clickLink(Wishlist['Check_Details'])

View File

@ -46,10 +46,10 @@ abstract class DuskTestCase extends BaseTestCase
)
);
}
// protected function baseUrl()
// {
// return 'http://beikeshop.test';
// }
protected function baseUrl()
{
return 'http://beikeshop.test';
}
/**
* Determine whether the Dusk command has disabled headless mode.