/** * @param \tests\codeception\frontend\AcceptanceTester $I * @param \Codeception\Scenario $scenario */ public function testUserSignup($I, $scenario) { $I->wantTo('ensure that signup works'); $signupPage = SignupPage::openBy($I); $I->see('Signup', 'h1'); $I->amGoingTo('submit signup form with no data'); $signupPage->submit([]); $I->expectTo('see validation errors'); $I->see('Username cannot be blank.', '.help-block'); $I->see('E-mail cannot be blank.', '.help-block'); $I->see('Password cannot be blank.', '.help-block'); $I->amGoingTo('submit signup form with not correct email'); $signupPage->submit(['username' => 'tester', 'email' => 'tester.email', 'password' => 'tester_password']); $I->expectTo('see that email address is wrong'); $I->dontSee('Username cannot be blank.', '.help-block'); $I->dontSee('Password cannot be blank.', '.help-block'); $I->see('E-mail is not a valid email address.', '.help-block'); $I->amGoingTo('submit signup form with correct email'); $signupPage->submit(['username' => 'tester', 'email' => '*****@*****.**', 'password' => 'tester_password']); if (method_exists($I, 'wait')) { $I->wait(3); // only for selenium } $I->expectTo('see that user logged in'); $I->click("tester", "a"); $I->see("Logout", "a"); }
/** * @env php */ public function testlanguageSwitcher(AcceptanceTester $I) { $I->wantTo('test language switcher'); $I->amOnPage('/'); $I->click(['link' => 'ru']); $I->seeCurrentUrlEquals('/index-test.php/ru'); }
/** * @param AcceptanceTester $I */ public function testView(AcceptanceTester $I) { $I->wantTo('ensure that term view page works'); $I->amOnPage(Url::to(['/term/view', 'id' => 1])); $I->see('Category: Sample Category', 'h1'); $I->seeLink('Sample Post'); $I->amOnPage(Url::to(['/term/view', 'term_slug' => 'sample-category'])); $I->see('Category: Sample Category', 'h1'); $I->seeLink('Sample Post'); }
/** * @param AcceptanceTester $I */ public function testView(AcceptanceTester $I) { $I->wantTo('ensure that user view page works'); $I->amOnPage(Url::to(['/user/view', 'id' => 1])); $I->see('All Posts By Super Administrator', 'h1'); $I->seeLink('Sample Post'); $I->amOnPage(Url::to(['/user/view', 'user' => 'superadmin'])); $I->see('All Posts By Super Administrator', 'h1'); $I->seeLink('Sample Post'); }
/** * @param \tests\codeception\frontend\AcceptanceTester $I * @param \Codeception\Scenario $scenario */ public function testUserSignup($I, $scenario) { $I->wantTo('ensure that signup works'); $signupPage = SignupPage::openBy($I); $I->see('Signup', 'h1'); $I->see('Please fill out the following fields to signup:'); $I->amGoingTo('submit signup form with no data'); $signupPage->submit([]); $I->expectTo('see validation errors'); $I->see('Email cannot be blank.', '.help-block'); $I->see('Password cannot be blank.', '.help-block'); $I->see('The verification code is incorrect', '.help-block'); $I->amGoingTo('submit signup form with not correct email'); $signupPage->submit(['email' => 'tester.email', 'password' => 'tester_password']); $I->expectTo('see that email address is wrong'); $I->dontSee('Password cannot be blank.', '.help-block'); $I->see('Email is not a valid email address.', '.help-block'); $I->amGoingTo('submit signup form with correct email'); $signupPage->submit(['email' => '*****@*****.**', 'password' => 'TesterPassword1', 'verifyCode' => 'testme']); $I->expectTo('see that user logged in'); $I->see('Logout (tester.email@example.com)', 'form button[type=submit]'); }
/** * @param AcceptanceTester $I * @param \Codeception\Scenario $scenario */ public function testUserSignup($I, $scenario) { $I->wantTo('ensure that signup works'); $signupPage = SignupPage::openBy($I); $I->see('Signup', 'h1'); $I->see('Please fill out the following fields to signup:'); $I->amGoingTo('submit signup form with no configs'); $signupPage->submit([]); $I->expectTo('see validation errors'); $I->see('Username cannot be blank.', '.help-block'); $I->see('Email cannot be blank.', '.help-block'); $I->see('Password cannot be blank.', '.help-block'); $I->amGoingTo('submit signup form with not correct email'); $signupPage->submit(['username' => 'tester', 'email' => 'tester.email', 'password' => 'tester_password']); $I->expectTo('see that email address is wrong'); $I->dontSee('Username cannot be blank.', '.help-block'); $I->dontSee('Password cannot be blank.', '.help-block'); $I->see('Email is not a valid email address.', '.help-block'); $I->amGoingTo('submit signup form with correct email'); $signupPage->submit(['username' => 'tester', 'email' => '*****@*****.**', 'password' => 'tester_password']); $I->expectTo('see that user logged in'); $I->seeLink('Logout (tester)'); }
<?php use tests\codeception\frontend\AcceptanceTester; use tests\codeception\common\_pages\LoginPage; $I = new AcceptanceTester($scenario); $I->wantTo('ensure login page works'); $loginPage = LoginPage::openBy($I); $I->amGoingTo('submit login form with no data'); $loginPage->login('', ''); $I->expectTo('see validations errors'); $I->see('Username cannot be blank.', '.help-block'); $I->see('Password cannot be blank.', '.help-block'); $I->amGoingTo('try to login with wrong credentials'); $I->expectTo('see validations errors'); $loginPage->login('admin', 'wrong'); $I->expectTo('see validations errors'); $I->see('Incorrect username or password.', '.help-block'); $I->amGoingTo('try to login with correct credentials'); $loginPage->login('erau', 'password_0'); $I->expectTo('see that user is logged'); $I->seeLink('Logout (erau)'); $I->dontSeeLink('Login'); $I->dontSeeLink('Signup'); /** Uncomment if using WebDriver * $I->click('Logout (erau)'); * $I->dontSeeLink('Logout (erau)'); * $I->seeLink('Login'); */
<?php use tests\codeception\frontend\AcceptanceTester; /* @var $scenario Codeception\Scenario */ $I = new AcceptanceTester($scenario); $I->wantTo('ensure that home page works'); $I->amOnPage(Yii::$app->homeUrl); $I->see('My Company'); $I->seeLink('About'); $I->click('About'); $I->see('This is the About page.');
<?php use tests\codeception\frontend\AcceptanceTester; use tests\codeception\frontend\_pages\demo\AboutPage; /* @var $scenario Codeception\Scenario */ $I = new AcceptanceTester($scenario); $I->wantTo('ensure that about works'); AboutPage::openBy($I); $I->see('About', 'h1');
<?php use tests\codeception\frontend\AcceptanceTester; use tests\codeception\frontend\_pages\ContactPage; /* @var $scenario Codeception\Scenario */ $I = new AcceptanceTester($scenario); $I->wantTo('ensure that contact works'); $contactPage = ContactPage::openBy($I); $I->see('Contact', 'h1'); $I->amGoingTo('submit contact form with no data'); $contactPage->submit([]); if (method_exists($I, 'wait')) { $I->wait(3); // only for selenium } $I->expectTo('see validations errors'); $I->see('Contact', 'h1'); $I->see('Name cannot be blank', '.help-block'); $I->see('Email cannot be blank', '.help-block'); $I->see('Subject cannot be blank', '.help-block'); $I->see('Body cannot be blank', '.help-block'); $I->see('The verification code is incorrect', '.help-block'); $I->amGoingTo('submit contact form with not correct email'); $contactPage->submit(['name' => 'tester', 'email' => 'tester.email', 'subject' => 'test subject', 'body' => 'test content', 'verifyCode' => 'testme']); if (method_exists($I, 'wait')) { $I->wait(3); // only for selenium } $I->expectTo('see that email adress is wrong'); $I->dontSee('Name cannot be blank', '.help-block'); $I->see('这不是一个有效的email地址!', '.help-block');
<?php use tests\codeception\frontend\AcceptanceTester; use tests\codeception\common\_pages\AccesoPage; /* @var $scenario Codeception\Scenario */ $I = new AcceptanceTester($scenario); $I->wantTo('asegurar que la pagina de inicio de sesión funciona'); $loginPage = AccesoPage::openBy($I); $I->amGoingTo('intentar acceder sin datos'); $loginPage->login('', ''); $I->expectTo('ver errores validacion'); $I->see('Correo no puede estar vacio', '.error-block'); $I->see('Clave no puede estar vacio', '.error-block'); $I->amGoingTo('intentar acceder con credenciales incorrectas'); $I->expectTo('ver errores validacion'); $loginPage->login('admin', 'wrong'); $I->expectTo('ver errores validacion'); $I->see('Usuario o clave es incorrecto.', '.error-block'); $I->amGoingTo('acceder con credenciales correctas'); $loginPage->login('erau', 'password_0'); $I->expectTo('ver que el usuario accede'); /** Uncomment if using WebDriver * $I->seeLink('Logout (erau)'); * $I->dontSeeLink('Crear cuenta'); * $I->dontSeeLink('Iniciar sesión'); */
<?php use tests\codeception\frontend\AcceptanceTester; /* @var $scenario Codeception\Scenario */ $I = new AcceptanceTester($scenario); $I->wantTo('ensure that home page works'); $I->amOnPage(Yii::$app->homeUrl); $I->see('Yii2 Starter Kit'); $I->seeLink('About'); $I->click('About'); $I->amOnPage('/page/about');
/** * @param AcceptanceTester $I */ public function testSearch(AcceptanceTester $I) { $I->wantTo('ensure that search page works'); $I->amOnPage(\Yii::$app->homeUrl); $I->submitForm('#sidebar .form-search', ['s' => 'test12345qwerty']); if (method_exists($I, 'wait')) { $I->wait(3); } $I->see('Not Found (#404)', 'h1'); $I->submitForm('#sidebar .form-search', ['s' => 'sample post']); if (method_exists($I, 'wait')) { $I->wait(3); } $I->seeLink('Sample Post'); }
<?php use tests\codeception\frontend\AcceptanceTester; /* @var $scenario Codeception\Scenario */ $I = new AcceptanceTester($scenario); $I->wantTo('ensure that home page works'); $I->amOnPage(Yii::$app->homeUrl); $I->see('<ul class="pagination">'); $I->seeLink('Гороскоп'); $I->click('Гороскоп'); $I->seeLink('Гороскопы на месяц');
<?php use tests\codeception\frontend\AcceptanceTester; /* @var $scenario Codeception\Scenario */ $I = new AcceptanceTester($scenario); $I->wantTo('ensure that home page works'); $I->amOnPage(Yii::$app->homeUrl); $I->see('My Yii Application'); $I->seeLink('Sing in'); $I->click('Sing in'); $I->see('Sign in to start your session');
<?php use tests\codeception\frontend\AcceptanceTester; use tests\codeception\common\_pages\LoginPage; use tests\codeception\frontend\_pages\UserPage; use tests\codeception\frontend\_pages\UserEditPage; /* @var $scenario Codeception\Scenario */ $I = new AcceptanceTester($scenario); $I->wantTo('Login view and update my profile'); $loginPage = LoginPage::openBy($I); $I->amGoingTo('Login with correct credentials'); $loginPage->login('erau', 'password_0'); $I->amGoingTo('ensure user profile page works'); $userPage = UserPage::openBy($I); $I->expectTo('see user personal data'); $I->see('*****@*****.**'); $I->seeLink('Edit my profile'); $I->amGoingTo('Open Edit my profile page'); $userEditPage = UserEditPage::openBy($I); $I->see('Edit my profile', 'h1'); $I->amGoingTo('update my profile with correct data'); $userEditPage->submit(['phone_mobile' => '+49 30 6840 978 167']); if (method_exists($I, 'wait')) { $I->wait(3); // only for selenium } $I->see('You profile has been updated.'); $I->see('+49 30 6840 978 167');
/** * @param AcceptanceTester $I */ public function testComment(AcceptanceTester $I) { $I->wantTo('ensure that post comment works'); $postView = PostViewPage::openBy($I); // $I->see('Sample Post', 'h1'); $I->see('Sample Post'); $I->amGoingTo('submit post comment form with no data'); $postView->submitComment([]); $I->expectTo('see validations error'); $I->see('Name cannot be blank.', '.help-block'); $I->see('Email cannot be blank.', '.help-block'); $I->see('Content cannot be blank.', '.help-block'); $I->amGoingTo('submit post comment form with no correct email'); $postView->submitComment(['comment_author' => 'tester', 'comment_author_email' => 'tester.email', 'comment_content' => 'New comment']); $I->expectTo('see that email is not correct'); $I->see('Email is not a valid email address.'); $I->dontSee('Name cannot be blank.', '.help-block'); $I->dontSee('Content cannot be blank.', '.help-block'); $I->amGoingTo('submit post comment form with correct data'); $postView->submitComment(['comment_author' => 'tester', 'comment_author_email' => '*****@*****.**', 'comment_content' => 'New comment']); $I->expect('new comment saved'); $I->dontSee('Name cannot be blank.', '.help-block'); $I->dontSee('Email cannot be blank.', '.help-block'); $I->dontSee('Content cannot be blank.', '.help-block'); PostComment::deleteAll(['comment_author' => 'tester']); Post::findOne(1)->updateAttributes(['post_comment_count' => '1']); }
<?php use tests\codeception\frontend\AcceptanceTester; use tests\codeception\frontend\_pages\SiteLoginPage; use Faker\Factory; $faker = Factory::create(); $I = new AcceptanceTester($scenario); $I->comment('Проверка авторизации пользователей'); $loginPage = SiteLoginPage::openBy($I); $I->wait(1); $I->seeInTitle(Yii::t('app', 'Login')); $I->seeElement('.main-login'); $I = new AcceptanceTester\SiteLoginSteps($scenario); $I->comment('Отправка пустой формы'); $loginPage->login('', ''); $I->wait(1); $I->see(Yii::t('yii', '{attribute} cannot be blank.', ['attribute' => $loginPage->getLoginFormAttribute('username')]), '.help-block'); $I->see(Yii::t('yii', '{attribute} cannot be blank.', ['attribute' => $loginPage->getLoginFormAttribute('password')]), '.help-block'); $I->comment('Отправка невнрных данных'); $loginPage->login($faker->email, 'неправильный пароль'); $I->wait(1); $I->see(Yii::t('app', 'Wrong phone, email or password.'), '.help-block');