123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909 |
- <?php
- use Codeception\Step;
- use Codeception\Util\Stub;
- use Facebook\WebDriver\Remote\RemoteWebDriver;
- use Facebook\WebDriver\WebDriverBy;
- use Facebook\WebDriver\WebDriverKeys;
- require_once codecept_data_dir() . 'app/data.php';
- require_once __DIR__ . '/../unit/Codeception/Module/TestsForBrowsers.php';
- class WebDriverTest extends TestsForBrowsers
- {
- /**
- * @var \Codeception\Module\WebDriver
- */
- protected $module;
- /**
- * @var RemoteWebDriver
- */
- protected $webDriver;
- const MODULE_CLASS = 'Codeception\Module\WebDriver';
- const WEBDRIVER_CLASS = 'Facebook\WebDriver\Remote\RemoteWebDriver';
- public function _before()
- {
- $this->module = $this->getModule('WebDriver');
- $this->webDriver = &$this->getModule('WebDriver')->webDriver;
- }
- public function _after()
- {
- data::clean();
- }
- public function testClickEventOnCheckbox()
- {
- $this->module->amOnPage('/form/checkbox');
- $this->module->uncheckOption('#checkin');
- $this->module->dontSee('ticked', '#notice');
- $this->module->checkOption('#checkin');
- $this->module->see('ticked', '#notice');
- }
- public function testAcceptPopup()
- {
- $this->notForPhantomJS();
- $this->module->amOnPage('/form/popup');
- $this->module->click('Confirm');
- $this->module->acceptPopup();
- $this->module->see('Yes', '#result');
- }
- public function testCancelPopup()
- {
- $this->notForPhantomJS();
- $this->module->amOnPage('/form/popup');
- $this->module->click('Confirm');
- $this->module->cancelPopup();
- $this->module->see('No', '#result');
- }
- public function testSelectByCss()
- {
- $this->module->amOnPage('/form/select');
- $this->module->selectOption('form select[name=age]', '21-60');
- $this->module->click('Submit');
- $form = data::get('form');
- $this->assertEquals('adult', $form['age']);
- }
- public function testSelectInvalidOptionForSecondSelectFails()
- {
- $this->shouldFail();
- $this->module->amOnPage('/form/select_second');
- $this->module->selectOption('#select2', 'Value2');
- }
- public function testSeeInPopup()
- {
- $this->notForPhantomJS();
- $this->module->amOnPage('/form/popup');
- $this->module->click('Alert');
- $this->module->seeInPopup('Really?');
- $this->module->cancelPopup();
- }
- public function testScreenshot()
- {
- $this->module->amOnPage('/');
- @unlink(\Codeception\Configuration::outputDir().'testshot.png');
- $testName="debugTest";
- $this->module->makeScreenshot($testName);
- $this->assertFileExists(\Codeception\Configuration::outputDir().'debug/'.$testName.'.png');
- @unlink(\Codeception\Configuration::outputDir().'debug/'.$testName.'.png');
- $this->module->_saveScreenshot(\Codeception\Configuration::outputDir().'testshot.png');
- $this->assertFileExists(\Codeception\Configuration::outputDir().'testshot.png');
- @unlink(\Codeception\Configuration::outputDir().'testshot.png');
- }
- public function testSubmitForm()
- {
- $this->module->amOnPage('/form/complex');
- $this->module->submitForm('form', [
- 'name' => 'Davert',
- 'age' => 'child',
- 'terms' => 'agree',
- 'description' => 'My Bio'
- ]);
- $form = data::get('form');
- $this->assertEquals('Davert', $form['name']);
- $this->assertEquals('kill_all', $form['action']);
- $this->assertEquals('My Bio', $form['description']);
- $this->assertEquals('agree', $form['terms']);
- $this->assertEquals('child', $form['age']);
- }
- public function testSubmitFormWithNumbers()
- {
- $this->module->amOnPage('/form/complex');
- $this->module->submitForm('form', [
- 'name' => 'Davert',
- 'age' => 'child',
- 'terms' => 'agree',
- 'description' => 10
- ]);
- $form = data::get('form');
- $this->assertEquals('Davert', $form['name']);
- $this->assertEquals('kill_all', $form['action']);
- $this->assertEquals('10', $form['description']);
- $this->assertEquals('agree', $form['terms']);
- $this->assertEquals('child', $form['age']);
- }
- /**
- * @dataProvider strictSelectorProvider
- */
- public function testSubmitFormWithButtonAsStrictSelector(array $selector)
- {
- $this->module->amOnPage('/form/strict_selectors');
- $this->module->submitForm('form', [
- 'name' => 'Davert',
- 'age' => 'child',
- 'terms' => 'agree',
- 'description' => 'My Bio'
- ], $selector);
- $form = data::get('form');
- $this->assertEquals('Davert', $form['name']);
- $this->assertEquals('kill_all', $form['action']);
- $this->assertEquals('My Bio', $form['description']);
- $this->assertEquals('agree', $form['terms']);
- $this->assertEquals('child', $form['age']);
- }
- public function strictSelectorProvider()
- {
- return [
- 'by id' => [['id' => 'submit_button']],
- 'by name' => [['name' => 'submit_button_name']],
- 'by css' => [['css' => 'form #submit_button']],
- 'by xpath' => [['xpath' => '//*[@id="submit_button"]']],
- 'by link' => [['link' => 'Submit']],
- 'by class' => [['class' => 'button']],
- ];
- }
- /**
- * @dataProvider webDriverByProvider
- */
- public function testSubmitFormWithButtonAsWebDriverBy(WebDriverBy $selector)
- {
- $this->module->amOnPage('/form/strict_selectors');
- $this->module->submitForm('form', [
- 'name' => 'Davert',
- 'age' => 'child',
- 'terms' => 'agree',
- 'description' => 'My Bio'
- ], $selector);
- $form = data::get('form');
- $this->assertEquals('Davert', $form['name']);
- $this->assertEquals('kill_all', $form['action']);
- $this->assertEquals('My Bio', $form['description']);
- $this->assertEquals('agree', $form['terms']);
- $this->assertEquals('child', $form['age']);
- }
- public function webDriverByProvider()
- {
- return [
- 'by id' => [WebDriverBy::id('submit_button')],
- 'by name' => [WebDriverBy::name('submit_button_name')],
- 'by css selector' => [WebDriverBy::cssSelector('form #submit_button')],
- 'by xpath' => [WebDriverBy::xpath('//*[@id="submit_button"]')],
- 'by link text' => [WebDriverBy::linkText('Submit')],
- 'by class name' => [WebDriverBy::className('button')],
- ];
- }
- public function testRadioButtonByValue()
- {
- $this->module->amOnPage('/form/radio');
- $this->module->selectOption('form', 'disagree');
- $this->module->click('Submit');
- $form = data::get('form');
- $this->assertEquals('disagree', $form['terms']);
- }
- public function testRadioButtonByLabelOnContext()
- {
- $this->module->amOnPage('/form/radio');
- $this->module->selectOption('form input', 'Get Off');
- $this->module->seeOptionIsSelected('form input', 'disagree');
- $this->module->dontSeeOptionIsSelected('form input', 'agree');
- $this->module->click('Submit');
- $form = data::get('form');
- $this->assertEquals('disagree', $form['terms']);
- }
- public function testRadioButtonByLabel()
- {
- $this->module->amOnPage('/form/radio');
- $this->module->checkOption('Get Off');
- $this->module->click('Submit');
- $form = data::get('form');
- $this->assertEquals('disagree', $form['terms']);
- }
- public function testRawSelenium()
- {
- $this->module->amOnPage('/');
- $this->module->executeInSelenium(function ($webdriver) {
- $webdriver->findElement(WebDriverBy::id('link'))->click();
- });
- $this->module->seeCurrentUrlEquals('/info');
- }
- public function testKeys()
- {
- $this->module->amOnPage('/form/field');
- $this->module->pressKey('#name', ['ctrl', 'a'], WebDriverKeys::DELETE);
- $this->module->pressKey('#name', 'test', ['shift', '111']);
- $this->module->pressKey('#name', '1');
- $this->module->seeInField('#name', 'test!!!1');
- }
- public function testWait()
- {
- $this->module->amOnPage('/');
- $time = time();
- $this->module->wait(3);
- $this->assertGreaterThanOrEqual($time+3, time());
- }
- public function testSelectInvalidOptionFails()
- {
- $this->shouldFail();
- $this->module->amOnPage('/form/select');
- $this->module->selectOption('#age', '13-22');
- }
- public function testAppendFieldSelect()
- {
- $this->module->amOnPage('/form/select_multiple');
- $this->module->selectOption('form #like', 'eat');
- $this->module->appendField('form #like', 'code');
- $this->module->click('Submit');
- $form = data::get('form');
- $this->assertEmpty(array_diff($form['like'], ["eat", "code"]));
- }
- public function testAppendFieldSelectFails()
- {
- $this->shouldFail();
- $this->module->amOnPage('/form/select_multiple');
- $this->module->appendField('form #like', 'code123');
- }
- public function testAppendFieldTextarea()
- {
- $this->module->amOnPage('/form/textarea');
- $this->module->fillField('form #description', 'eat');
- $this->module->appendField('form #description', ' code');
- $this->module->click('Submit');
- $form = data::get('form');
- $this->assertEquals('eat code', $form['description']);
- }
- public function testAppendFieldTextareaFails()
- {
- $this->shouldFail();
- $this->module->amOnPage('/form/textarea');
- $this->module->appendField('form #description123', ' code');
- }
- public function testAppendFieldText()
- {
- $this->module->amOnPage('/form/field');
- $this->module->appendField('form #name', ' code');
- $this->module->click('Submit');
- $form = data::get('form');
- $this->assertEquals('OLD_VALUE code', $form['name']);
- }
- public function testAppendFieldTextFails()
- {
- $this->shouldFail();
- $this->module->amOnPage('/form/field');
- $this->module->appendField('form #name123', ' code');
- }
- public function testAppendFieldCheckboxByValue()
- {
- $this->module->amOnPage('/form/checkbox');
- $this->module->appendField('form input[name=terms]', 'agree');
- $this->module->click('Submit');
- $form = data::get('form');
- $this->assertEquals('agree', $form['terms']);
- }
- public function testAppendFieldCheckboxByValueFails()
- {
- $this->shouldFail();
- $this->module->amOnPage('/form/checkbox');
- $this->module->appendField('form input[name=terms]', 'agree123');
- }
- public function testAppendFieldCheckboxByLabel()
- {
- $this->module->amOnPage('/form/checkbox');
- $this->module->appendField('form input[name=terms]', 'I Agree');
- $this->module->click('Submit');
- $form = data::get('form');
- $this->assertEquals('agree', $form['terms']);
- }
- public function testAppendFieldCheckboxByLabelFails()
- {
- $this->shouldFail();
- $this->module->amOnPage('/form/checkbox');
- $this->module->appendField('form input[name=terms]', 'I Agree123');
- }
- public function testAppendFieldRadioButtonByValue()
- {
- $this->module->amOnPage('/form/radio');
- $this->module->appendField('form input[name=terms]', 'disagree');
- $this->module->click('Submit');
- $form = data::get('form');
- $this->assertEquals('disagree', $form['terms']);
- }
- public function testAppendFieldRadioButtonByValueFails()
- {
- $this->shouldFail();
- $this->module->amOnPage('/form/radio');
- $this->module->appendField('form input[name=terms]', 'disagree123');
- }
- public function testAppendFieldRadioButtonByLabel()
- {
- $this->module->amOnPage('/form/radio');
- $this->module->appendField('form input[name=terms]', 'Get Off');
- $this->module->click('Submit');
- $form = data::get('form');
- $this->assertEquals('disagree', $form['terms']);
- }
- public function testAppendFieldRadioButtonByLabelFails()
- {
- $this->shouldFail();
- $this->module->amOnPage('/form/radio');
- $this->module->appendField('form input[name=terms]', 'Get Off123');
- }
- public function testPauseExecution()
- {
- $this->module->amOnPage('/');
- $this->module->pauseExecution();
- }
- // Issue https://github.com/Codeception/Codeception/pull/875
- public function testFillPasswordOnFormSubmit()
- {
- $this->module->amOnPage('/form/complex');
- $this->module->submitForm('form', [
- 'password' => '123456'
- ]);
- $form = data::get('form');
- $this->assertEquals('123456', $form['password']);
- }
- public function testEmptyFormSubmit()
- {
- $this->shouldFail();
- $this->module->amOnPage('/form/complex');
- $this->module->submitForm('form111', []);
- }
- public function testWebDriverByLocators()
- {
- $this->module->amOnPage('/login');
- $this->module->seeElement(WebDriverBy::id('submit-label'));
- $this->module->seeElement(WebDriverBy::name('password'));
- $this->module->seeElement(WebDriverBy::className('optional'));
- $this->module->seeElement(WebDriverBy::cssSelector('form.global_form_box'));
- $this->module->seeElement(WebDriverBy::xpath(\Codeception\Util\Locator::tabIndex(4)));
- $this->module->fillField(WebDriverBy::name('password'), '123456');
- $this->module->amOnPage('/form/select');
- $this->module->selectOption(WebDriverBy::name('age'), 'child');
- $this->module->amOnPage('/form/checkbox');
- $this->module->checkOption(WebDriverBy::name('terms'));
- $this->module->amOnPage('/');
- $this->module->seeElement(WebDriverBy::linkText('Test'));
- $this->module->click(WebDriverBy::linkText('Test'));
- $this->module->seeCurrentUrlEquals('/form/hidden');
- }
- public function testSeeVisible()
- {
- $this->module->amOnPage('/info');
- $this->module->dontSee('Invisible text');
- $this->module->dontSee('Invisible', '.hidden');
- $this->module->seeInPageSource('Invisible text');
- }
- public function testSeeInvisible()
- {
- $this->shouldFail();
- $this->module->amOnPage('/info');
- $this->module->see('Invisible text');
- }
- public function testFailWebDriverByLocator()
- {
- $this->shouldFail();
- $this->module->amOnPage('/form/checkbox');
- $this->module->checkOption(WebDriverBy::name('age'));
- }
- // fails in PhpBrowser :(
- public function testSubmitUnchecked()
- {
- $this->module->amOnPage('/form/unchecked');
- $this->module->seeCheckboxIsChecked('#checkbox');
- $this->module->uncheckOption('#checkbox');
- $this->module->click('#submit');
- ;
- $this->module->see('0', '#notice');
- }
- public function testCreateCeptScreenshotFail()
- {
- $fakeWd = Stub::make('\Facebook\WebDriver\Remote\RemoteWebDriver', [
- 'takeScreenshot' => Stub::once(function () {
- }),
- 'getPageSource' => Stub::once(function () {
- }),
- 'manage' => Stub::make('\Facebook\WebDriver\WebDriverOptions', [
- 'getAvailableLogTypes' => Stub::atLeastOnce(function () {
- return [];
- }),
- ]),
- ]);
- $module = Stub::make(self::MODULE_CLASS, ['webDriver' => $fakeWd]);
- $cept = (new \Codeception\Test\Cept('loginCept', 'loginCept.php'));
- $module->_failed($cept, new PHPUnit_Framework_AssertionFailedError());
- }
- public function testCreateCestScreenshotOnFail()
- {
- $fakeWd = Stub::make(self::WEBDRIVER_CLASS, [
- 'takeScreenshot' => Stub::once(function ($filename) {
- PHPUnit_Framework_Assert::assertEquals(codecept_log_dir('stdClass.login.fail.png'), $filename);
- }),
- 'getPageSource' => Stub::once(function () {
- }),
- 'manage' => Stub::make('\Facebook\WebDriver\WebDriverOptions', [
- 'getAvailableLogTypes' => Stub::atLeastOnce(function () {
- return [];
- }),
- ]),
- ]);
- $module = Stub::make(self::MODULE_CLASS, ['webDriver' => $fakeWd]);
- $cest = new \Codeception\Test\Cest(new stdClass(), 'login', 'someCest.php');
- $module->_failed($cest, new PHPUnit_Framework_AssertionFailedError());
- }
- public function testCreateTestScreenshotOnFail()
- {
- $test = Stub::make('\Codeception\TestCase\Test', ['getName' => 'testLogin']);
- $fakeWd = Stub::make(self::WEBDRIVER_CLASS, [
- 'takeScreenshot' => Stub::once(function ($filename) use ($test) {
- PHPUnit_Framework_Assert::assertEquals(
- codecept_log_dir(get_class($test).'.testLogin.fail.png'),
- $filename
- );
- }),
- 'getPageSource' => Stub::once(function () {
- }),
- 'manage' => Stub::make('\Facebook\WebDriver\WebDriverOptions', [
- 'getAvailableLogTypes' => Stub::atLeastOnce(function () {
- return [];
- }),
- ]),
- ]);
- $module = Stub::make(self::MODULE_CLASS, ['webDriver' => $fakeWd]);
- $module->_failed($test, new PHPUnit_Framework_AssertionFailedError());
- }
- public function testWebDriverWaits()
- {
- $fakeWd = Stub::make(self::WEBDRIVER_CLASS, ['wait' => Stub::exactly(12, function () {
- return new \Codeception\Util\Maybe();
- })]);
- $module = Stub::make(self::MODULE_CLASS, ['webDriver' => $fakeWd]);
- $module->waitForElement(WebDriverBy::partialLinkText('yeah'));
- $module->waitForElement(['id' => 'user']);
- $module->waitForElement(['css' => '.user']);
- $module->waitForElement('//xpath');
- $module->waitForElementVisible(WebDriverBy::partialLinkText('yeah'));
- $module->waitForElementVisible(['id' => 'user']);
- $module->waitForElementVisible(['css' => '.user']);
- $module->waitForElementVisible('//xpath');
- $module->waitForElementNotVisible(WebDriverBy::partialLinkText('yeah'));
- $module->waitForElementNotVisible(['id' => 'user']);
- $module->waitForElementNotVisible(['css' => '.user']);
- $module->waitForElementNotVisible('//xpath');
- }
- public function testBug1467()
- {
- $this->module->amOnPage('/form/bug1467');
- $this->module->selectOption('form[name=form2] input[name=first_test_radio]', 'Yes');
- $this->module->selectOption('form[name=form2] input[name=second_test_radio]', 'No');
- $this->module->seeOptionIsSelected('form[name=form2] input[name=first_test_radio]', 'Yes');
- $this->module->seeOptionIsSelected('form[name=form2] input[name=second_test_radio]', 'No');
- // shouldn't have touched form1 at all
- $this->module->dontSeeOptionIsSelected('form[name=form1] input[name=first_test_radio]', 'No');
- $this->module->dontSeeOptionIsSelected('form[name=form1] input[name=first_test_radio]', 'Yes');
- $this->module->dontSeeOptionIsSelected('form[name=form1] input[name=second_test_radio]', 'No');
- $this->module->dontSeeOptionIsSelected('form[name=form1] input[name=second_test_radio]', 'Yes');
- }
- /**
- * @Issue 1598
- */
- public function testWaitForTextBug1598()
- {
- $this->module->amOnPage('/form/bug1598');
- $this->module->waitForText('12,345', 10, '#field');
- }
- public function testSeeElementMalformedWdLocator()
- {
- $this->setExpectedException('Codeception\Exception\MalformedLocatorException');
- $this->module->amOnPage('/');
- $this->module->seeElement(WebDriverBy::xpath('H---EY!'));
- }
- public function testBug1637()
- {
- $this->module->amOnPage('/form/bug1637');
- // confirm that options outside a form are still selectable
- $this->module->selectOption('input[name=first_test_radio]', 'Yes');
- // confirm that it did what we expected and did not do anything else
- $this->module->seeOptionIsSelected('input[name=first_test_radio]', 'Yes');
- $this->module->dontSeeOptionIsSelected('input[name=first_test_radio]', 'No');
- }
- public function testBug2046()
- {
- $this->module->webDriver = null;
- $this->module->_saveScreenshot(\Codeception\Configuration::outputDir().'testshot.png');
- }
- public function testSessionSnapshots()
- {
- $this->notForPhantomJS();
- $this->module->amOnPage('/');
- $this->module->setCookie('PHPSESSID', '123456', ['path' => '/']);
- $this->module->saveSessionSnapshot('login');
- $this->module->seeCookie('PHPSESSID');
- $this->webDriver->manage()->deleteAllCookies();
- $this->module->dontSeeCookie('PHPSESSID');
- $this->module->loadSessionSnapshot('login');
- $this->module->seeCookie('PHPSESSID');
- }
- public function testSaveSessionSnapshotsExcludeInvalidCookieDomains()
- {
- $this->notForPhantomJS();
- $fakeWdOptions = Stub::make('\Facebook\WebDriver\WebDriverOptions', [
- 'getCookies' => Stub::atLeastOnce(function () {
- return [
- [
- 'name' => 'PHPSESSID',
- 'value' => '123456',
- 'path' => '/',
- ],
- [
- 'name' => '3rdParty',
- 'value' => '_value_',
- 'path' => '/',
- 'domain' => '.3rd-party.net',
- ]
- ];
- }),
- ]);
- $fakeWd = Stub::make(self::WEBDRIVER_CLASS, [
- 'manage' => Stub::atLeastOnce(function () use ($fakeWdOptions) {
- return $fakeWdOptions;
- }),
- ]);
- // Mock the WebDriverOptions::getCookies() method on the first call to introduce a 3rd-party cookie
- // which has to be ignored when saving a snapshot.
- $originalWebDriver = $this->module->webDriver;
- $this->module->webDriver = $fakeWd;
- $this->module->seeCookie('PHPSESSID');
- $this->module->seeCookie('3rdParty');
- $this->module->saveSessionSnapshot('login');
- // Restore the original WebDriver
- $this->module->webDriver = $originalWebDriver;
- $this->webDriver->manage()->deleteAllCookies();
- $this->module->dontSeeCookie('PHPSESSID');
- $this->module->dontSeeCookie('3rdParty');
- $this->module->loadSessionSnapshot('login');
- $this->module->seeCookie('PHPSESSID');
- $this->module->dontSeeCookie('3rdParty');
- }
- public function testSeeInFieldTextarea()
- {
- $this->module->amOnPage('/form/textarea');
- //make sure we see 'sunrise' which is the default text in the textarea
- $this->module->seeInField('#description', 'sunrise');
- if ($this->notForSelenium()) {
- $this->module->seeInField('#whitespaces', ' no_whitespaces ');
- }
- $this->module->seeInField('#whitespaces', 'no_whitespaces');
- //fill in some new text and see if we can see it
- $textarea_value = 'test string';
- $this->module->fillField('#description', $textarea_value);
- $this->module->seeInField('#description', $textarea_value);
- }
- public function testSeeInFieldSelect()
- {
- $this->module->amOnPage('/form/select_second');
- if ($this->notForSelenium()) {
- $this->module->seeInField('#select2', ' no_whitespaces ');
- }
- $this->module->seeInField('#select2', 'no_whitespaces');
- // select new option and check it
- $option_value = 'select2_value1';
- $this->module->selectOption('#select2', $option_value);
- $this->module->seeInField('#select2', $option_value);
- }
- public function testAppendFieldDiv()
- {
- $this->notForPhantomJS();
- $this->module->amOnPage('/form/div_content_editable');
- //make sure we see 'sunrise' which is the default text in the textarea
- $this->module->see('sunrise', '#description');
- //fill in some new text and see if we can see it
- $textarea_value = 'moonrise';
- $this->module->appendField('#description', $textarea_value);
- $this->module->see('sunrise' . $textarea_value, '#description');
- }
- public function testOpenPageException()
- {
- if (!$this->module->_getConfig('restart')) {
- $this->markTestSkipped('works only on restarts');
- }
- parent::testOpenPageException();
- }
- public function testCookies()
- {
- $this->notForPhantomJS();
- parent::testCookies();
- }
- public function testSendingCookies()
- {
- $this->notForPhantomJS();
- parent::testSendingCookies();
- }
- public function testCookiesWithPath()
- {
- $this->notForPhantomJS();
- parent::testCookiesWithPath();
- }
- protected function notForPhantomJS()
- {
- if ($this->module->_getConfig('browser') == 'phantomjs') {
- $this->markTestSkipped('does not work for phantomjs');
- }
- }
- protected function notForSelenium()
- {
- if ($this->module->_getConfig('browser') != 'phantom') {
- $this->markTestSkipped('does not work for selenium');
- }
- }
- public function testScrollTo()
- {
- $this->module->amOnPage('/form/example18');
- $this->module->scrollTo('#clickme');
- $this->module->click('Submit');
- $this->module->see('Welcome to test app!');
- }
- /**
- * @Issue 2921
- */
- public function testSeeInFieldForTextarea()
- {
- $this->module->amOnPage('/form/bug2921');
- $this->module->seeInField('foo', 'bar baz');
- }
- public function testClickHashLink()
- {
- $this->module->amOnPage('/form/anchor');
- $this->module->click('Hash Link');
- $this->module->seeCurrentUrlEquals('/form/anchor#b');
- }
- /**
- * @Issue 3865
- */
- public function testClickNumericLink()
- {
- $this->module->amOnPage('/form/bug3865');
- $this->module->click('222');
- $this->module->see('Welcome to test app');
- }
- public function testClickHashButton()
- {
- $this->module->amOnPage('/form/anchor');
- $this->module->click('Hash Button');
- $this->module->seeCurrentUrlEquals('/form/anchor#c');
- }
- public function testSubmitHashForm()
- {
- $this->module->amOnPage('/form/anchor');
- $this->module->click('Hash Form');
- $this->module->seeCurrentUrlEquals('/form/anchor#a');
- }
- public function testJSErrorLoggingPositive()
- {
- // arrange
- $this->module->_setConfig(['log_js_errors' => true]);
- $cept = new \Codeception\Test\Cept('foo', 'bar');
- // act
- $this->module->amOnPage('/jserroronload');
- $this->module->_failed($cept, 'anyFailMessage');
- // assert
- /* @var $steps Step[] */
- $steps = $cept->getScenario()->getSteps();
- $this->assertGreaterThan(0, count($steps));
- $lastStep = end($steps);
- $this->assertContains(
- "TypeError",
- $lastStep->getHtml()
- );
- }
- public function testJSErrorLoggingNegative()
- {
- // arrange
- $this->module->_setConfig(['log_js_errors' => false]);
- $cept = new \Codeception\Test\Cept('foo', 'bar');
- // act
- $this->module->amOnPage('/jserroronload');
- $this->module->_failed($cept, 'anyFailMessage');
- // assert
- /* @var $steps Step[] */
- $steps = $cept->getScenario()->getSteps();
- $this->assertEquals(0, count($steps));
- }
- public function testMoveMouseOver()
- {
- $this->module->amOnPage('/form/click');
- $this->module->moveMouseOver(null, 123, 88);
- $this->module->clickWithLeftButton(null, 0, 0);
- $this->module->see('click, offsetX: 123 - offsetY: 88');
- $this->module->moveMouseOver(null, 10, 10);
- $this->module->clickWithLeftButton(null, 0, 0);
- $this->module->see('click, offsetX: 133 - offsetY: 98');
- $this->module->moveMouseOver('#element2');
- $this->module->clickWithLeftButton(null, 0, 0);
- $this->module->see('click, offsetX: 58 - offsetY: 158');
- $this->module->moveMouseOver('#element2', 0, 0);
- $this->module->clickWithLeftButton(null, 0, 0);
- $this->module->see('click, offsetX: 8 - offsetY: 108');
- }
- public function testLeftClick()
- {
- $this->module->amOnPage('/form/click');
- $this->module->clickWithLeftButton(null, 123, 88);
- $this->module->see('click, offsetX: 123 - offsetY: 88');
- $this->module->clickWithLeftButton('body');
- $this->module->see('click, offsetX: 600 - offsetY: 384');
- $this->module->clickWithLeftButton('body', 50, 75);
- $this->module->see('click, offsetX: 58 - offsetY: 83');
- $this->module->clickWithLeftButton('body div');
- $this->module->see('click, offsetX: 58 - offsetY: 58');
- $this->module->clickWithLeftButton('#element2', 70, 75);
- $this->module->see('click, offsetX: 78 - offsetY: 183');
- }
- public function testRightClick()
- {
- // actually not supported in phantomjs see https://github.com/ariya/phantomjs/issues/14005
- $this->notForPhantomJS();
- $this->module->amOnPage('/form/click');
- $this->module->clickWithRightButton(null, 123, 88);
- $this->module->see('context, offsetX: 123 - offsetY: 88');
- $this->module->clickWithRightButton('body');
- $this->module->see('context, offsetX: 600 - offsetY: 384');
- $this->module->clickWithRightButton('body', 50, 75);
- $this->module->see('context, offsetX: 58 - offsetY: 83');
- $this->module->clickWithRightButton('body div');
- $this->module->see('context, offsetX: 58 - offsetY: 58');
- $this->module->clickWithRightButton('#element2', 70, 75);
- $this->module->see('context, offsetX: 78 - offsetY: 183');
- }
- public function testBrowserTabs()
- {
- $this->notForPhantomJS();
- $this->module->amOnPage('/form/example1');
- $this->module->openNewTab();
- $this->module->amOnPage('/form/example2');
- $this->module->openNewTab();
- $this->module->amOnPage('/form/example3');
- $this->module->openNewTab();
- $this->module->amOnPage('/form/example4');
- $this->module->openNewTab();
- $this->module->amOnPage('/form/example5');
- $this->module->closeTab();
- $this->module->seeInCurrentUrl('example4');
- $this->module->switchToPreviousTab(2);
- $this->module->seeInCurrentUrl('example2');
- $this->module->switchToNextTab();
- $this->module->seeInCurrentUrl('example3');
- $this->module->closeTab();
- $this->module->seeInCurrentUrl('example2');
- $this->module->switchToNextTab(2);
- $this->module->seeInCurrentUrl('example1');
- }
- }
|