public function testSubmitForm() { $this->module->amOnPage('/form/complex'); $this->module->submitForm('form', array('name' => 'Davert')); $form = data::get('form'); $this->assertEquals('Davert', $form['name']); $this->assertEquals('kill_all', $form['action']); }
public function beforeTest(\Codeception\Event\Test $e) { if (!$this->module) { return; } $cookie = array('CodeCoverage' => $e->getTest()->getName(), 'CodeCoverage_Suite' => $this->suite_name, 'CodeCoverage_Config' => $this->settings['remote_config']); $this->module->amOnPage('/'); $this->module->setCookie('CODECEPTION_CODECOVERAGE', json_encode($cookie)); }
public function testSwitchToIframe() { $this->module->amOnPage('/iframe'); $this->module->switchToIframe('content'); $this->module->see('Is that interesting?'); $this->module->click('Ссылочка'); }
/** * @issue https://github.com/Codeception/Codeception/issues/2841 */ public function testSubmitFormDoesNotKeepGetParameters() { $this->module->amOnPage('/form/bug2841?stuff=other'); $this->module->fillField('#texty', 'thingshjere'); $this->module->click('#submit-registration'); $this->assertEmpty(data::get('query'), 'Query string is not empty'); }
public function testLoginToFacebook() { $this->markTestSkipped(); // preconditions: #1 php web server being run $browserModule = new PhpBrowser(); $browserModule->_setConfig(array('url' => 'http://localhost:8000')); $browserModule->_initialize(); $browserModule->_cleanup(); $browserModule->_before($this->makeTest()); SuiteManager::$modules['PhpBrowser'] = $browserModule; // preconditions: #2 facebook test user was created $this->module->haveFacebookTestUserAccount(); $testUserFirstName = $this->module->grabFacebookTestUserFirstName(); // preconditions: #3 test user logged in on facebook $this->module->haveTestUserLoggedInOnFacebook(); // go to our page with facebook login button $browserModule->amOnPage('/facebook'); // check that yet we are not logged in with facebook $browserModule->see('You are not Connected.'); // click on "Login with Facebook" button to start login with facebook $browserModule->click('Login with Facebook'); // check that we are logged in with facebook $browserModule->see('Your User Object (/me)'); $browserModule->see($testUserFirstName); // cleanup unset(SuiteManager::$modules['PhpBrowser']); $browserModule->_after($this->makeTest()); data::clean(); }
public function testSeeElementOnPage() { $this->module->amOnPage('/form/field'); $this->module->seeElement('input[name=name]'); $this->module->seeElement('descendant-or-self::input[@id="name"]'); $this->module->dontSeeElement('#something-beyond'); $this->module->dontSeeElement('descendant-or-self::input[@id="something-beyond"]'); }
public function testFillFieldWithAmpersand() { $this->module->amOnPage('/form/field'); $this->module->fillField('Name', 'this & that'); $this->module->click('Submit'); $form = data::get('form'); $this->assertEquals('this & that', $form['name']); }
public function testSubmitFormWithoutButton() { $this->module->amOnPage('/form/empty'); $this->module->submitForm('form', array( 'text' => 'Hello!' )); $form = data::get('form'); $this->assertEquals('Hello!', $form['text']); }
public function testArrayFieldSubmitForm() { $this->module->amOnPage('/form/example17'); $this->module->submitForm('form', ['FooBar' => ['bar' => 'booze'], 'Food' => ['beer' => ['yum' => ['yeah' => 'crunked']]]]); $data = data::get('form'); $this->assertEquals('booze', $data['FooBar']['bar']); $this->assertEquals('crunked', $data['Food']['beer']['yum']['yeah']); }
/** * @issue https://github.com/Codeception/Codeception/issues/2234 */ public function testEmptyValueOfCookie() { //set cookie $this->module->amOnPage('/cookies2'); $this->module->amOnPage('/unset-cookie'); $this->module->seeResponseCodeIs(200); $this->module->dontSeeCookie('a'); }
/** * If we have a form with fields like * ``` * <input type="file" name="foo" /> * <input type="file" name="foo[bar]" /> * ``` * then only array variable will be used while simple variable will be ignored in php $_FILES * (eg $_FILES = [ * foo => [ * tmp_name => [ * 'bar' => 'asdf' * ], * //... * ] * ] * ) * (notice there is no entry for file "foo", only for file "foo[bar]" * this will check if current element contains inner arrays within it's keys * so we can ignore element itself and only process inner files */ public function testFormWithFilesInOnlyArray() { $this->shouldFail(); $this->module->amOnPage('/form/example13'); $this->module->attachFile('foo', 'app/avatar.jpg'); $this->module->attachFile('foo[bar]', 'app/avatar.jpg'); $this->module->click('Submit'); }
public function testSelectOptionTextSelector() { $this->module->amOnPage('/form/select_selectors'); $this->module->selectOption('age', ['text' => '20']); $this->module->seeOptionIsSelected('age', '20'); $this->module->selectOption('age', ['text' => '21']); $this->module->seeOptionIsSelected('age', '21'); }
public function testSubmitAdjacentForms() { $this->module->amOnPage('/form/submit_adjacentforms'); $this->module->submitForm('#form-2', []); $data = data::get('form'); $this->assertTrue(isset($data['second-field'])); $this->assertFalse(isset($data['first-field'])); $this->assertEquals('Killgore Trout', $data['second-field']); }
public function testMultipleCookies() { $this->module->amOnPage('/'); $this->module->sendAjaxPostRequest('/cookies'); $this->module->seeCookie('foo', 'bar1'); $this->module->seeCookie('baz', 'bar2'); $this->module->setCookie('foo', 'bar1'); $this->module->setCookie('baz', 'bar2'); $this->module->amOnPage('/cookies'); $this->module->seeInCurrentUrl('info'); }
public function testFormWithFileSpecialCharNames() { $this->module->amOnPage('/form/example14'); $this->module->attachFile('foo bar', 'app/avatar.jpg'); $this->module->attachFile('foo.baz', 'app/avatar.jpg'); $this->module->click('Submit'); $this->assertNotEmpty(data::get('files')); $files = data::get('files'); $this->assertNotEmpty($files); $this->assertArrayHasKey('foo_bar', $files); $this->assertArrayHasKey('foo_baz', $files); }
/** * @Issue https://github.com/Codeception/Codeception/issues/1585 * @Issue https://github.com/Codeception/Codeception/issues/1602 */ public function testUnreachableField() { $this->module->amOnPage('/form/bug1585'); $this->module->fillField('textarea[name="captions[]"]', 'test2'); $this->module->fillField('items[1][]', 'test3'); $this->module->fillField('input[name="users[]"]', 'davert'); $this->module->attachFile('input[name="files[]"]', 'app/avatar.jpg'); $this->module->click('Submit'); $data = data::get('form'); $this->assertContains('test3', $data['items'][1]); $this->assertContains('test2', $data['captions']); $this->assertContains('davert', $data['users']); }
public function testSelectAndCheckOptionSquareBracketNames() { $this->module->amOnPage('/form/names-sq-brackets'); $this->module->selectOption('//input[@name="input_radio_name"]', '1'); $this->module->selectOption('//input[@name="input_radio_name"]', '2'); $this->module->checkOption('//input[@name="input_checkbox_name"]', '1'); $this->module->checkOption('//input[@name="input_checkbox_name"]', '2'); $this->module->checkOption('//input[@name="input[checkbox][name][]"]', '1'); $this->module->checkOption('//input[@name="input[checkbox][name][]"]', '2'); $this->module->checkOption('//input[@name="input[checkbox][name][]"]', '1'); $this->module->selectOption('//select[@name="select_name"]', '1'); $this->module->selectOption('//input[@name="input[radio][name][]"]', '1'); $this->module->selectOption('//input[@name="input[radio][name][]"]', '2'); $this->module->selectOption('//input[@name="input[radio][name][]"]', '1'); $this->module->selectOption('//select[@name="select[name][]"]', '1'); }
public function testGrabMultiple() { $this->module->amOnPage('/info'); $arr = $this->module->grabMultiple('#grab-multiple a:first-child'); $this->assertCount(1, $arr); $this->assertEquals('First', $arr[0]); $arr = $this->module->grabMultiple('#grab-multiple a'); $this->assertCount(3, $arr); $this->assertEquals('First', $arr[0]); $this->assertEquals('Second', $arr[1]); $this->assertEquals('Third', $arr[2]); // href for WebDriver with selenium returns a full link, so testing with ID $arr = $this->module->grabMultiple('#grab-multiple a', 'id'); $this->assertCount(3, $arr); $this->assertEquals('first-link', $arr[0]); $this->assertEquals('second-link', $arr[1]); $this->assertEquals('third-link', $arr[2]); }
/** * @issue https://github.com/Codeception/Codeception/issues/2408 */ public function testClickFailure() { $this->module->amOnPage('/info'); $this->setExpectedException('Codeception\\Exception\\ElementNotFound', "'Sign In!' is invalid CSS and XPath selector and Link or Button element with 'name=Sign In!' was not found"); $this->module->click('Sign In!'); }
public function testLinksWithNonLatin() { $this->module->amOnPage('/info'); $this->module->seeLink('Ссылочка'); $this->module->click('Ссылочка'); }
public function testDontSeeElementOnPageFails() { $this->shouldFail(); $this->module->amOnPage('/form/field'); $this->module->dontSeeElement('descendant-or-self::input[@id="name"]'); }
/** * Get facebook test user be logged in on facebook. * * @throws ModuleConfigException */ public function haveTestUserLoggedInOnFacebook() { if (!array_key_exists('id', $this->testUser)) { throw new ModuleException(__CLASS__, 'Facebook test user was not found. Did you forget to create one?'); } // go to facebook and make login; it work only if you visit facebook.com first $this->phpBrowser->amOnPage('https://www.facebook.com/'); $this->phpBrowser->sendAjaxPostRequest('login.php', ['email' => $this->grabFacebookTestUserEmail(), 'pass' => $this->testUser['password']]); $this->phpBrowser->see($this->grabFacebookTestUserName()); }
public function testArrayField() { $this->module->amOnPage('/form/example17'); $this->module->seeInField('input[name="FooBar[bar]"]', 'baz'); $this->module->seeInField('input[name="Food[beer][yum][yeah]"]', 'mmhm'); }
public function testApostrophesInText() { $this->module->amOnPage('/info'); $this->module->see("Don't do that at home!"); $this->module->see("Don't do that at home!", 'h3'); }
private function loginToFacebook(PhpBrowser $browserModule) { // preconditions: #1 facebook test user is created $this->module->haveFacebookTestUserAccount(); $testUserName = $this->module->grabFacebookTestUserName(); // preconditions: #2 test user is logged in on facebook $this->module->haveTestUserLoggedInOnFacebook(); // go to our page with facebook login button $browserModule->amOnPage('/facebook'); // check that yet we are not logged in on facebook $browserModule->see('You are not Connected.'); // click on "Login with Facebook" button to start login with facebook $browserModule->click('Login with Facebook'); // check that we are logged in with facebook $browserModule->see('Your User Object (/me)'); $browserModule->see($testUserName); }
public function testCanInspectResultOfPhpBrowserRequest() { $this->phpBrowser->amOnPage('/rest/user/'); $this->module->seeResponseCodeIs(200); $this->module->seeResponseIsJson(); }
public function testFieldWithNonLatin() { $this->module->amOnPage('/info'); $this->module->seeInField('rus', 'Верно'); }
public function testHeadersBySetHeader() { $this->module->setHeader('xxx', 'yyyy'); $this->module->amOnPage('/'); $this->assertTrue($this->history->getLastRequest()->hasHeader('xxx')); }