登录多场景

This commit is contained in:
licy@guangda.work 2023-04-10 18:17:49 +08:00 committed by Edward Yang
parent 6ed7d11368
commit 1f7e2e9942
14 changed files with 782 additions and 5 deletions

View File

@ -1,8 +1,8 @@
APP_NAME=BeikeShop
APP_ENV=local
APP_KEY=base64:3RBtk9D81bfkLAjZ8UK7TSsIsHU+UBukSXx754Rkw1I=
APP_KEY=base64:jtXAebXemawRVp7IsA+xQXYtGdxFSvzWZ3Xh2zoHFVc=
APP_DEBUG=true
APP_URL=
APP_URL=http://autotest.test
APP_TIMEZONE=PRC
APP_FORCE_HTTPS=false
ASSET_URL=
@ -14,11 +14,11 @@ LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_HOST=192.168.0.111
DB_PORT=3306
DB_DATABASE=beike
DB_DATABASE=lcy_autoobeike
DB_USERNAME=root
DB_PASSWORD=
DB_PASSWORD='123456'
BROADCAST_DRIVER=log
CACHE_DRIVER=file

View File

@ -33,6 +33,7 @@
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.6",
"codeception/codeception": "^5.0",
"fakerphp/faker": "^1.9.1",
"laravel-lang/attributes": "^1.0",
"laravel-lang/lang": "^10.9",

298
composer.lock generated
View File

@ -8135,6 +8135,304 @@
],
"time": "2023-02-04T15:47:28+00:00"
},
{
"name": "behat/gherkin",
"version": "v4.9.0",
"source": {
"type": "git",
"url": "https://github.com/Behat/Gherkin.git",
"reference": "0bc8d1e30e96183e4f36db9dc79caead300beff4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Behat/Gherkin/zipball/0bc8d1e30e96183e4f36db9dc79caead300beff4",
"reference": "0bc8d1e30e96183e4f36db9dc79caead300beff4",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": "~7.2|~8.0"
},
"require-dev": {
"cucumber/cucumber": "dev-gherkin-22.0.0",
"phpunit/phpunit": "~8|~9",
"symfony/yaml": "~3|~4|~5"
},
"suggest": {
"symfony/yaml": "If you want to parse features, represented in YAML files"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.x-dev"
}
},
"autoload": {
"psr-0": {
"Behat\\Gherkin": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Konstantin Kudryashov",
"email": "ever.zet@gmail.com",
"homepage": "http://everzet.com"
}
],
"description": "Gherkin DSL parser for PHP",
"homepage": "http://behat.org/",
"keywords": [
"BDD",
"Behat",
"Cucumber",
"DSL",
"gherkin",
"parser"
],
"support": {
"issues": "https://github.com/Behat/Gherkin/issues",
"source": "https://github.com/Behat/Gherkin/tree/v4.9.0"
},
"time": "2021-10-12T13:05:09+00:00"
},
{
"name": "codeception/codeception",
"version": "5.0.10",
"source": {
"type": "git",
"url": "https://github.com/Codeception/Codeception.git",
"reference": "ed4af7fd4103cdd035916fbb8f35124edd2d018b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Codeception/Codeception/zipball/ed4af7fd4103cdd035916fbb8f35124edd2d018b",
"reference": "ed4af7fd4103cdd035916fbb8f35124edd2d018b",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"behat/gherkin": "^4.6.2",
"codeception/lib-asserts": "^2.0",
"codeception/stub": "^4.1",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"php": "^8.0",
"phpunit/php-code-coverage": "^9.2 || ^10.0",
"phpunit/php-text-template": "^2.0 || ^3.0",
"phpunit/php-timer": "^5.0.3 || ^6.0",
"phpunit/phpunit": "^9.5.20 || ^10.0",
"psy/psysh": "^0.11.2",
"sebastian/comparator": "^4.0.5 || ^5.0",
"sebastian/diff": "^4.0.3 || ^5.0",
"symfony/console": ">=4.4.24 <7.0",
"symfony/css-selector": ">=4.4.24 <7.0",
"symfony/event-dispatcher": ">=4.4.24 <7.0",
"symfony/finder": ">=4.4.24 <7.0",
"symfony/var-dumper": ">=4.4.24 < 7.0",
"symfony/yaml": ">=4.4.24 <7.0"
},
"conflict": {
"codeception/lib-innerbrowser": "<3.1.3",
"codeception/module-filesystem": "<3.0",
"codeception/module-phpbrowser": "<2.5"
},
"replace": {
"codeception/phpunit-wrapper": "*"
},
"require-dev": {
"codeception/lib-innerbrowser": "*@dev",
"codeception/lib-web": "^1.0",
"codeception/module-asserts": "*@dev",
"codeception/module-cli": "*@dev",
"codeception/module-db": "*@dev",
"codeception/module-filesystem": "*@dev",
"codeception/module-phpbrowser": "*@dev",
"codeception/util-universalframework": "*@dev",
"ext-simplexml": "*",
"jetbrains/phpstorm-attributes": "^1.0",
"symfony/dotenv": ">=4.4.24 <7.0",
"symfony/process": ">=4.4.24 <7.0",
"vlucas/phpdotenv": "^5.1"
},
"suggest": {
"codeception/specify": "BDD-style code blocks",
"codeception/verify": "BDD-style assertions",
"ext-simplexml": "For loading params from XML files",
"stecman/symfony-console-completion": "For BASH autocompletion",
"symfony/dotenv": "For loading params from .env files",
"symfony/phpunit-bridge": "For phpunit-bridge support",
"vlucas/phpdotenv": "For loading params from .env files"
},
"bin": [
"codecept"
],
"type": "library",
"autoload": {
"files": [
"functions.php"
],
"psr-4": {
"Codeception\\": "src/Codeception",
"Codeception\\Extension\\": "ext"
},
"classmap": [
"src/PHPUnit/TestCase.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Bodnarchuk",
"email": "davert.ua@gmail.com",
"homepage": "https://codeception.com"
}
],
"description": "BDD-style testing framework",
"homepage": "https://codeception.com/",
"keywords": [
"BDD",
"TDD",
"acceptance testing",
"functional testing",
"unit testing"
],
"support": {
"issues": "https://github.com/Codeception/Codeception/issues",
"source": "https://github.com/Codeception/Codeception/tree/5.0.10"
},
"funding": [
{
"url": "https://opencollective.com/codeception",
"type": "open_collective"
}
],
"time": "2023-03-14T07:21:10+00:00"
},
{
"name": "codeception/lib-asserts",
"version": "2.1.0",
"source": {
"type": "git",
"url": "https://github.com/Codeception/lib-asserts.git",
"reference": "b8c7dff552249e560879c682ba44a4b963af91bc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Codeception/lib-asserts/zipball/b8c7dff552249e560879c682ba44a4b963af91bc",
"reference": "b8c7dff552249e560879c682ba44a4b963af91bc",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"codeception/phpunit-wrapper": "^7.7.1 | ^8.0.3 | ^9.0",
"ext-dom": "*",
"php": "^7.4 | ^8.0"
},
"type": "library",
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Bodnarchuk",
"email": "davert@mail.ua",
"homepage": "http://codegyre.com"
},
{
"name": "Gintautas Miselis"
},
{
"name": "Gustavo Nieves",
"homepage": "https://medium.com/@ganieves"
}
],
"description": "Assertion methods used by Codeception core and Asserts module",
"homepage": "https://codeception.com/",
"keywords": [
"codeception"
],
"support": {
"issues": "https://github.com/Codeception/lib-asserts/issues",
"source": "https://github.com/Codeception/lib-asserts/tree/2.1.0"
},
"time": "2023-02-10T18:36:23+00:00"
},
{
"name": "codeception/stub",
"version": "4.1.0",
"source": {
"type": "git",
"url": "https://github.com/Codeception/Stub.git",
"reference": "58751aed08a68ae960a952fd3fe74ee9a56cdb1b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Codeception/Stub/zipball/58751aed08a68ae960a952fd3fe74ee9a56cdb1b",
"reference": "58751aed08a68ae960a952fd3fe74ee9a56cdb1b",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": "^7.4 | ^8.0",
"phpunit/phpunit": "^8.4 | ^9.0 | ^10.0 | 10.0.x-dev"
},
"conflict": {
"codeception/codeception": "<5.0.6"
},
"require-dev": {
"consolidation/robo": "^3.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Codeception\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Flexible Stub wrapper for PHPUnit's Mock Builder",
"support": {
"issues": "https://github.com/Codeception/Stub/issues",
"source": "https://github.com/Codeception/Stub/tree/4.1.0"
},
"time": "2022-12-27T18:41:43+00:00"
},
{
"name": "doctrine/instantiator",
"version": "1.5.0",

16
phpunit.dusk.xml Normal file
View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Browser Test Suite">
<directory suffix="Test.php">./tests/Browser</directory>
</testsuite>
</testsuites>
</phpunit>

0
public/nginx.htaccess Normal file
View File

View File

@ -0,0 +1,48 @@
<?php
namespace Tests\Browser;
namespace App\Http\Controllers;
namespace App\Http\Controllers\login;
namespace App\Http\Controllers\TestCase;
use App\Http\Controllers\LoginGrounp;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
use App\Http\Controllers\By;
use PHPUnit\Framework\TestCase;
require_once 'vendor/autoload.php';
require_once(dirname(__FILE__) . '/../page/front/loginGrounp.php');
class Run_Login_Case extends DuskTestCase
{
/**
* A basic browser test example.
*/
public function runScenarios(array $scenarios)
{
foreach ($scenarios as $scenario) {
$this->$scenario();
}
}
public function test_login_run()
{
$Loginful = new LoginGrounp();
$Loginful->openurl();
// $this->runScenarios([
// 'openurl',
// 'ture_email',
// 'ture_password',
// 'click_login_btn',
// 'ture_assert',
// ]);
}
}

View File

@ -0,0 +1,17 @@
<?php
const true_login = [
'email' => 'test@163.com',
'password' => '123456',
'assert' => 'Sign Out',
];
const false_login = [
'false_email' => 'test1@163.com',
'illegal_email' => 'test',
'false_password' => '1234567',
'false_assert' => 'User login and registration',
'illegal_assert' => 'Please enter a valid email address!',
];

View File

@ -0,0 +1,23 @@
<?php
const login = [
"login_url" =>"/login",
"login_email"=> "#page-login > div.login-wrap > div:nth-child(1) > form > div.card-body.px-md-2 > div:nth-child(1) > div > div > input",
"login_pwd"=> "#page-login > div.login-wrap > div:nth-child(1) > form > div.card-body.px-md-2 > div:nth-child(2) > div > div > input",
"login_btn"=> "Login",
"login_text"=> "Home",
"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 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",
];

View File

@ -0,0 +1,8 @@
<?php
const ture = [
'email' => 'test@163.com',
'password' => '123456',
're_password'=> '123456',
];

View File

@ -0,0 +1,82 @@
<?php
namespace Tests\Browser\Pages;
use Laravel\Dusk\Browser;
class HomePage
{
/**
* The URL of the page.
*
* @var string
*/
protected $url = '/';
/**
* Assert that the browser is on the page.
*
* @param Browser $browser
* @return void
*/
public function assert(Browser $browser)
{
$browser->assertPathIs($this->url);
}
/**
* Get the page URL.
*
* @return string
*/
public function url()
{
return $this->url;
}
/**
* Click on the login link.
*
* @param Browser $browser
* @return void
*/
public function clickLoginLink(Browser $browser)
{
$browser->clickLink('Login');
}
/**
* Fill in the email field.
*
* @param Browser $browser
* @param string $email
* @return void
*/
public function fillInEmailField(Browser $browser, $email)
{
$browser->type('input[name="email"]', $email);
}
/**
* Fill in the password field.
*
* @param Browser $browser
* @param string $password
* @return void
*/
public function fillInPasswordField(Browser $browser, $password)
{
$browser->type('input[name="password"]', $password);
}
/**
* Submit the login form.
*
* @param Browser $browser
* @return void
*/
public function submitLoginForm(Browser $browser)
{
$browser->press('Login');
}
}

View File

@ -0,0 +1,155 @@
<?php
namespace Tests\Browser;
namespace App\Http\Controllers;
namespace App\Http\Controllers\LoginGrounp;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
use App\Http\Controllers\By;
require_once(dirname(__FILE__) . '/../../data/login.php');
require_once(dirname(__FILE__) . '/../../data/login_page.php');
class LoginGrounp extends DuskTestCase
{
// const LOGIN_DATA = [
// 'aa'
// ];
/**
* A basic browser test example.
*/
public function runScenarios(array $scenarios)
{
foreach ($scenarios as $scenario) {
$this->$scenario();
}
}
#1.打开浏览器
public function openurl()
{
$this->browse(function (Browser $browser) {
$browser->visit(login['login_url'])
->pause(2000);
});
}
#输入正确email
public function true_email()
{
$this->browse(function (Browser $browser) {
$browser->type(login['login_email'], true_login['email']);
});
}
#输入错误的email
public function false_email()
{
$this->browse(function (Browser $browser) {
$browser->type(login['login_email'], false_login['false_email']);
});
}
#输入非法的email
public function illegal_email()
{
$this->browse(function (Browser $browser) {
$browser->type(login['login_email'], false_login['illegal_email']);
});
}
#输入正确的password
public function true_password()
{
$this->browse(function (Browser $browser) {
$browser->type(login['login_pwd'], true_login['password']);
});
}
#输入错误的password
public function false_password()
{
$this->browse(function (Browser $browser) {
$browser->type(login['login_pwd'], false_login['false_password']);
});
}
#点击login
public function click_login_btn()
{
$this->browse(function (Browser $browser) {
$browser->press(login['login_btn']);
});
}
#登录正确断言
public function true_assert()
{
$this->browse(function (Browser $browser) {
$browser->assertSee(true_login['assert'])
->pause(3000)
->quit();
});
}
#登录错误断言
public function false_assert()
{
$this->browse(function (Browser $browser) {
$browser->assertSee(false_login['false_assert'])
->pause(3000)
->quit();
});
}
#组合测试
#场景1---密码账号正确
public function test_login_ful()
{
$this->runScenarios([
'openurl',
'true_email',
'true_password',
'click_login_btn'=> function (Browser $browser) {
$browser->pause(1000) // 等待页面跳转
->assertPathIs('/account');
},
'true_assert' => function (Browser $browser) {
$browser->assertSee('欢迎回来!');
},
]);
}
#场景2---密码错误、账号正确
public function test_pwd_error()
{
$this->runScenarios([
'openurl',
'true_email',
'false_password',
'click_login_btn',
'false_assert',
]);
}
#场景3---密码正确、账号错误
public function test_email_error()
{
$this->runScenarios([
'openurl',
'false_email',
'true_password',
'click_login_btn',
'false_assert',
]);
}
#场景4---密码正确、账号非法
public function test_email_illegal()
{
$this->runScenarios([
'openurl',
'false_email',
'illegal_email',
'click_login_btn',
'false_assert',
]);
}
}

View File

@ -0,0 +1,93 @@
<?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/login.php');
require_once(dirname(__FILE__) . '/../../data/login_page.php');
class LoginTest extends DuskTestCase
{
/**
* A basic browser test example.
*/
//场景2 email不合法
public function testEmailIllegal(): void
{
parent::setUp();
$this->browse(function (Browser $browser)
{
$browser->visit(login['login_url'])
->pause(2000)
->type(login['login_email'], false_login['illegal_email'])
->type(login['login_pwd'], true_login['password'])
->press(login['login_btn'])
->waitForReload() //等待页面重载
->assertSee(false_login['illegal_assert'])
->pause(3000)
->quit();
});
}
//场景3 email不存在
public function testEmaiFalse(): void
{
parent::setUp();
$this->browse(function (Browser $browser)
{
$browser->visit(login['login_url'])
->pause(2000)
->type(login['login_email'], false_login['false_email'])
->type(login['login_pwd'], true_login['password'])
->press(login['login_btn'])
->waitForReload() //等待页面重载
->assertSee(false_login['false_assert'])
->pause(3000)
->quit();
});
}
//场景4 密码错误
public function testPwdFalse(): void
{
parent::setUp();
$this->browse(function (Browser $browser)
{
$browser->visit(login['login_url'])
->pause(2000)
->type(login['login_email'], false_login['false_email'])
->type(login['login_pwd'], false_login['false_password'])
->press(login['login_btn'])
->waitForReload() //等待页面重载
->assertSee(false_login['false_assert'])
->pause(3000)
->quit();
});
}
//场景1 成功登录
public function testLoginFul(): void
{
parent::setUp(); // 重置测试环境和状态
$this->browse(function (Browser $browser)
{
$browser->visit(login['login_url'])
->pause(2000)
->type(login['login_email'], true_login['email'])
->type(login['login_pwd'], true_login['password'])
->press(login['login_btn'])
->waitForReload() //等待页面重载
->assertSee(true_login['assert'])
->pause(3000)
->quit();
});
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace Tests\Browser;
namespace App\Http\Controllers;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
require_once 'E:\phpstudy_pro\WWW\autotest.test\beikeshop\tests\Browser\dusktest\data\login_page.php';
require_once 'E:\phpstudy_pro\WWW\autotest.test\beikeshop\tests\Browser\dusktest\data\register.php';
class RegisterTest extends DuskTestCase
{
/**
* A basic browser test example.
*/
public function testRegisterTest(): void
{
// $user = User::factory()->create([
// 'email' => 'test@163.com',
// ]);
$this->browse(function (Browser $browser) {
$browser->visit(login['login_url'])
->pause(2000)
->type(register['register_email'], ture['email'])
->type(register['register_pwd'], ture['password'])
->type(register['register_re_pwd'], ture['re_password'])
->press(register['register_btn'])
->assertSee(register['register_text'])
->pause(3000);
});
}
}

View File

@ -21,6 +21,7 @@ abstract class DuskTestCase extends BaseTestCase
{
if (! static::runningInSail()) {
static::startChromeDriver();
// static::startFirefoxDriver();
}
}