/**
  * Поиск продукта по названию и переход на страницу
  * @param  String $link_text
  * @return Page_Product
  */
 public function click_product_by_link_text($link_text)
 {
     $wait = new WebDriverWait($this->web_driver, 30);
     $wait->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::linkText($link_text)));
     $this->web_driver->findElement(WebDriverBy::linkText($link_text))->click();
     return new Page_Product($this->web_driver);
 }
 /**
  * @test
  */
 public function 質問ページから質問投稿する()
 {
     //        $basic_user = '******';
     //        $basic_pass = '******';
     //        $gooid_user = '******';
     //        $gooid_pass = '******';
     //        $domain = '*****.goo.ne.jp';
     require __DIR__ . '/../config.php';
     $basic_user = urlencode($basic_user);
     $basic_pass = urlencode($basic_pass);
     $title = 'タイトル' . time();
     $description = '本文' . time();
     $driver = Util::createDriver();
     Util::loginToGoo($driver, $gooid_user, $gooid_pass);
     $driver->get("http://{$basic_user}:{$basic_pass}@{$domain}/question");
     $driver->findElement(\WebDriverBy::id('title_area'))->sendKeys($title);
     $driver->findElement(\WebDriverBy::id('text_area'))->sendKeys($description);
     $driver->findElement(\WebDriverBy::cssSelector('#question_confirm_btn > a > span.q-text'))->click();
     Util::skipPageLenvingAlert($driver);
     $driver->wait(5)->until(\WebDriverExpectedCondition::visibilityOfElementLocated(\WebDriverBy::cssSelector('#match_categories > input')));
     $driver->findElement(\WebDriverBy::cssSelector('#question_complete_button > a'))->click();
     $driver->findElement(\WebDriverBy::cssSelector('li.tooSeeBtn > a'))->click();
     $actual_title = $driver->getTitle();
     $url = $driver->getCurrentUrl();
     preg_match('/\\/qa\\/(\\d+)\\.html/', $url, $matches);
     $qid = $matches[1];
     $trimed_title = preg_replace('/ - .+/', '', $actual_title);
     echo $actual_title . "\n";
     echo $url . "\n";
     echo $qid . "\n";
     $driver->quit();
     $this->assertEquals($title, $trimed_title);
 }
Example #3
0
 public function testProcessOrder()
 {
     $this->driver->get($this->getTestPath('/admin'));
     $this->driver->findElement(WebDriverBy::id('username'))->sendKeys('admin');
     $this->driver->findElement(WebDriverBy::id('login'))->sendKeys('P@ssw0rd');
     $this->driver->findElement(WebDriverBy::className('form-button'))->click();
     $this->driver->findElement(WebDriverBy::xpath("//span[text()='Sales']"))->click();
     $this->driver->findElement(WebDriverBy::xpath("//span[text()='Orders']"))->click();
     $this->driver->wait()->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::id('sales_order_grid_filter_real_order_id')));
     $this->driver->findElement(WebDriverBy::id('sales_order_grid_filter_real_order_id'))->sendKeys('ICANN-D10000014');
     $this->driver->findElement(WebDriverBy::id('sales_order_grid_filter_real_order_id'))->sendKeys(WebDriverKeys::ENTER);
     sleep(3);
     $this->driver->findElement(WebDriverBy::xpath("//html/body/div[1]/div[2]/div/div[3]/div/div[2]/div/table/tbody/tr[1]/td[2]"))->click();
     $this->driver->findElement(WebDriverBy::xpath("//span[text()='Invoice']"))->click();
     $this->driver->findElement(WebDriverBy::xpath("//span[text()='Submit Invoice']"))->click();
     $this->driver->findElement(WebDriverBy::xpath("//span[text()='Ship']"))->click();
     $this->driver->findElement(WebDriverBy::xpath("//span[text()='Add Tracking Number']"))->click();
     $this->driver->findElement(WebDriverBy::id("trackingC1"))->click();
     $this->driver->findElement(WebDriverBy::xpath("//select[@id='trackingC1']/option[@value='fedex']"))->click();
     $this->driver->findElement(WebDriverBy::id("trackingT1"))->sendKeys('FEDEX');
     $this->driver->findElement(WebDriverBy::id("trackingN1"))->sendKeys('Tracking0001');
     $this->driver->findElement(WebDriverBy::id("send_email"))->click();
     $this->driver->findElement(WebDriverBy::xpath("//span[text()='Submit Shipment']"))->click();
     sleep(5);
 }
 /**
  * @param  RemoteWebDriver $web_driver
  */
 function __construct(RemoteWebDriver $web_driver)
 {
     $this->web_driver = $web_driver;
     // Дожидаемся загрузки первого елемента(кнопка Add to cart)
     $wait = new WebDriverWait($this->web_driver, 30);
     $wait->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::id('MainContent_btn_addToCart')));
     $this->colors = $this->init_select();
     $this->sizes = $this->init_select_sizes();
 }
 public function testLimitReachedDismisses()
 {
     $this->set_api_key('LIMIT123');
     $this->upload_image(dirname(__FILE__) . '/../fixtures/input-example.png');
     self::$driver->findElement(WebDriverBy::cssSelector('.tiny-notice button, .tiny-notice a.tiny-dismiss'))->click();
     self::$driver->wait(2)->until(WebDriverExpectedCondition::invisibilityOfElementWithText(WebDriverBy::cssSelector('.tiny-dismiss'), 'Dismiss'));
     self::$driver->get(wordpress('/wp-admin/options-media.php'));
     $this->assertEquals(0, count(self::$driver->findElements(WebDriverBy::cssSelector('div.error p'))));
 }
 public function testIncorrectJsonButton()
 {
     $this->enable_compression_sizes(array());
     $this->upload_image(dirname(__FILE__) . '/../fixtures/input-example.png');
     $this->enable_compression_sizes(array('medium', 'large'));
     $this->set_api_key('JSON1234');
     self::$driver->get(wordpress('/wp-admin/upload.php'));
     self::$driver->findElement(WebDriverBy::cssSelector('td.tiny-compress-images button'))->click();
     self::$driver->wait(2)->until(WebDriverExpectedCondition::textToBePresentInElement(WebDriverBy::cssSelector('td.tiny-compress-images'), 'JSON: Syntax error [4]'));
 }
 /**
  * @param  RemoteWebDriver $web_driver
  */
 function __construct(RemoteWebDriver $web_driver)
 {
     $this->web_driver = $web_driver;
     // Дожидаемся загрузки первого елемента
     $wait = new WebDriverWait($this->web_driver, 30);
     $wait->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::id('MainContent_Email')));
     $this->email = $this->web_driver->findElement(WebDriverBy::id('MainContent_Email'));
     $this->password = $this->web_driver->findElement(WebDriverBy::id('MainContent_Password'));
     $this->remember = $this->web_driver->findElement(WebDriverBy::id('MainContent_RememberMe'));
     $this->submit = $this->web_driver->findElement(WebDriverBy::name('ctl00$MainContent$ctl05'));
 }
Example #8
0
 /**
  * Set value of Select2 element
  * @param string $originalId ID of original select/input element
  * @param string $value Value to be selected
  * @param bool $multiSelect OPTIONAL Is the select multiselect?
  * @todo Support multiple values for multiselects
  */
 public function setSelect2Value($originalId, $value, $multiSelect = false)
 {
     $select2selector = '#s2id_' . $originalId;
     // Wait for select2 to appear
     $select2link = $this->tc->wd->wait()->until(\WebDriverExpectedCondition::presenceOfElementLocated(\WebDriverBy::cssSelector($select2selector . ' ' . ($multiSelect ? 'input' : 'a'))));
     // Click on element to open dropdown - to copy users behavior
     $select2link->click();
     $this->log('Sending keys to select2: %s', $value);
     // Insert searched term into s2 generated input
     $this->tc->wd->findElement(\WebDriverBy::cssSelector($multiSelect ? $select2selector . ' input' : '#select2-drop input'))->sendKeys($value);
     // Wait until result are rendered (or maybe loaded with ajax)
     $firstResult = $this->tc->wd->wait()->until(\WebDriverExpectedCondition::presenceOfElementLocated(\WebDriverBy::cssSelector('.select2-drop .select2-result.select2-highlighted')));
     $this->log('Dropdown detected, selecting the first result: %s', $firstResult->getText());
     // Select first item in results
     $firstResult->click();
 }
 public function testBulkCompressShouldCompressAll()
 {
     $this->prepare(1, 1);
     self::$driver->get(wordpress('/wp-admin/upload.php?page=tiny-bulk-compress.php'));
     $elements = self::$driver->findElements(WebDriverBy::cssSelector('#tiny-bulk-compress p'));
     $this->assertContains('2 images', $elements[1]->getText());
     self::$driver->findElement(WebDriverBy::cssSelector('#tiny-bulk-compress button'))->click();
     self::$driver->wait(2)->until(WebDriverExpectedCondition::textToBePresentInElement(WebDriverBy::cssSelector('.updated'), 'All images are processed'));
     $elements = self::$driver->findElements(WebDriverBy::cssSelector('.media-item .filename'));
     $filenames = array_map('innerText', $elements);
     $this->assertEquals(2, count($filenames));
     $this->assertContains('input-large', $filenames);
     $this->assertContains('input-example', $filenames);
     $this->assertEquals('2', self::$driver->findElement(WebDriverBy::cssSelector('#tiny-progress span'))->getText());
     $this->assertEquals('5', self::$driver->findElement(WebDriverBy::cssSelector('#tiny-status span'))->getText());
 }
Example #10
0
 function testDataDictSearchKeywordFilters()
 {
     $this->webDriver->get($this->url . "/datadict/");
     $this->webDriver->wait(120, 1000)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::Name("keyword")));
     $searchKey = $this->webDriver->findElements(WebDriverBy::Name("keyword"));
     switch (count($searchKey)) {
         case 1:
             break;
         case 0:
             $this->fail("Could not find search keyword field");
             return;
         default:
             $this->fail("Too many search keyword fields.");
             return;
     }
     $searchKey[0]->sendKeys("NotRealMAGICNUMBER335");
     $searchButton = $this->webDriver->findElement(WebDriverBy::Name("filter"));
     $searchButton->click();
     $this->markTestSkipped("Data Dict test not yet updated for React");
     /*
     		try {
        while (true) {
            $oldBody->isDisplayed();
             }
     		} catch(Exception $e) {
     			$this->webDriver->executescript("document.documentElement.outerHTML");
     
     		}
     */
     $rows = $this->webDriver->findElements(WebDriverBy::cssSelector("table tbody tr"));
     $this->assertTrue(count($rows) == 1, "Incorrect number of rows returned when filtering for keyword on datadict" . print_r($rows, true));
     $cols = $this->webDriver->findElements(WebDriverBy::cssSelector("table tbody tr td"));
     // Rownumber
     $this->assertEquals($cols[0]->getText(), "1");
     // SourceFrom
     $this->assertEquals($cols[1]->getText(), "nowhere");
     // Name
     $this->assertEquals($cols[2]->getText(), "TestParameterNotRealMAGICNUMBER335");
     // SourceField
     $this->assertEquals($cols[3]->getText(), "imaginary");
     // Description
     $this->assertEquals($cols[4]->getText(), "I am a fake description used only for testing you should not see me. MAGICNUMBER335");
 }
 protected function upload_image($path)
 {
     self::$driver->get(wordpress('/wp-admin/media-new.php?browser-uploader&flash=0'));
     $links = self::$driver->findElements(WebDriverBy::xpath('//a[text()="browser uploader"]'));
     if (count($links) > 0) {
         $link = $links[0];
         if ($link->isDisplayed()) {
             $link->click();
         }
     }
     self::$driver->wait(2)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::name('async-upload')));
     $file_input = self::$driver->findElement(WebDriverBy::name('async-upload'));
     $file_input->setFileDetector(new LocalFileDetector());
     $file_input->sendKeys($path);
     self::$driver->findElement(WebDriverBy::xpath('//input[@value="Upload"]'))->click();
     $path_elements = explode('/', $path);
     $file_name = array_pop($path_elements);
     $image_elements = explode('.', $file_name);
     $image_name = $image_elements[0];
     self::$driver->wait(2)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::xpath('//img[contains(@src, "' . $image_name . '")]')));
 }
Example #12
0
<?php

// An example of using php-webdriver.
require_once 'lib/__init__.php';
// start Firefox with 5 second timeout
$host = 'http://localhost:4444/wd/hub';
// this is the default
$capabilities = array(WebDriverCapabilityType::BROWSER_NAME => 'firefox');
$driver = RemoteWebDriver::create($host, $capabilities, 5000);
// navigate to 'http://docs.seleniumhq.org/'
$driver->get('http://docs.seleniumhq.org/');
// adding cookie
$driver->manage()->deleteAllCookies();
$driver->manage()->addCookie(array('name' => 'cookie_name', 'value' => 'cookie_value'));
$cookies = $driver->manage()->getCookies();
print_r($cookies);
// click the link 'About'
$link = $driver->findElement(WebDriverBy::id('menu_about'));
$link->click();
// print the title of the current page
echo "The title is " . $driver->getTitle() . "'\n";
// print the title of the current page
echo "The current URI is " . $driver->getCurrentURL() . "'\n";
// Search 'php' in the search box
$input = $driver->findElement(WebDriverBy::id('q'));
$input->sendKeys('php')->submit();
// wait at most 10 seconds until at least one result is shown
$driver->wait(10)->until(WebDriverExpectedCondition::presenceOfAllElementsLocatedBy(WebDriverBy::className('gsc-result')));
// close the Firefox
$driver->quit();
Example #13
0
 /**
  * Pause for a given number of seconds
  *
  * @param int $timeout_in_second
  * @return $this
  * @throws NoSuchElementException
  * @author Ronan Chilvers <*****@*****.**>
  */
 public function waitForSelector($selector, $timeout_in_second = 30, $interval_in_millisecond = 250)
 {
     $by = $this->getWebDriverBy($selector);
     $this->wait($timeout_in_second, $interval_in_millisecond)->until(\WebDriverExpectedCondition::presenceOfElementLocated($by));
     return $this;
 }
Example #14
0
 /**
  * Compares the content of the candidate table with an expected content.
  *
  * @param string $tableName    name of the HTML table.
  * @param string $expectedRows array of candidates that the table should contain.
  *
  * @return void
  */
 private function _assertCandidateTableContents($tableName, $expectedRows)
 {
     if (is_null($expectedRows)) {
         $wait = new WebDriverWait($this->webDriver, 15);
         $wait->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::ClassName('no-result-found-panel')));
         $element = $this->webDriver->findElement(WebDriverBy::ClassName('no-result-found-panel'));
         $this->assertContains('No result found', $element->getText());
     } else {
         $wait = new WebDriverWait($this->webDriver, 15);
         $wait->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::Id('dynamictable')));
         $dataTable = $this->webDriver->findElement(WebDriverBy::Id('dynamictable'));
         $actualRows = $dataTable->findElements(WebDriverBy::xpath('.//tbody//tr'));
         $this->assertEquals(count($actualRows), count($expectedRows), "Number of candidates returned should be " . count($expectedRows) . ", not " . count($actualRows));
         for ($i = 0; $i < count($actualRows); $i++) {
             $elements = $actualRows[$i]->findElements(WebDriverBy::xpath('.//td'));
             $actualColumns = array();
             foreach ($elements as $e) {
                 $actualColumns[] = $e->getText();
             }
             $expectedColumns = $expectedRows[$i];
             $this->assertEquals($actualColumns, $expectedColumns, "Candidates at row {$i} differ");
         }
     }
 }
 /**
  * An expectation with the logical opposite condition of the given condition.
  *
  * @param WebDriverExpectedCondition $condition The condition to be negated.
  * @return mixed The nagation of the result of the given condition.
  */
 public static function not(WebDriverExpectedCondition $condition)
 {
     return new WebDriverExpectedCondition(function ($driver) use($condition) {
         $result = call_user_func($condition->getApply(), $driver);
         return !$result;
     });
 }
Example #16
0
 /**
  * Waits up to $timeout seconds for the given string to appear on the page.
  * Can also be passed a selector to search in.
  * If the given text doesn't appear, a timeout exception is thrown.
  *
  * ``` php
  * <?php
  * $I->waitForText('foo', 30); // secs
  * $I->waitForText('foo', 30, '.title'); // secs
  * ?>
  * ```
  *
  * @param string $text
  * @param int $timeout seconds
  * @param null $selector
  * @throws \Exception
  */
 public function waitForText($text, $timeout = 10, $selector = null)
 {
     if (!$selector) {
         $condition = \WebDriverExpectedCondition::textToBePresentInElement(\WebDriverBy::xpath('//body'), $text);
         $this->webDriver->wait($timeout)->until($condition);
         return;
     }
     $condition = \WebDriverExpectedCondition::textToBePresentInElement($this->getLocator($selector), $text);
     $this->webDriver->wait($timeout)->until($condition);
 }
 public function testStatusPresenseFail()
 {
     $this->set_api_key('INVALID123');
     self::$driver->wait(2)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::cssSelector('#tiny-compress-status p')));
     $elements = self::$driver->findElement(WebDriverBy::id('tiny-compress-status'))->findElements(WebDriverBy::tagName('p'));
     $statuses = array_map('innerText', $elements);
     $this->assertContains('API connection unsuccessful', $statuses);
 }
Example #18
0
 /**
  * Wait until page title partially matches given string
  *
  * @param string $title The expected title substring
  * @return \RemoteWebElement|array
  */
 public function waitForPartialTitle($title)
 {
     return $this->wd->wait()->until(\WebDriverExpectedCondition::titleContains($title));
 }
Example #19
0
 /**
  * @param string $selector
  * @param string $text
  * @param int $timeout
  */
 public function waitForText($selector, $text, $timeout = null)
 {
     $this->_wait($timeout)->until(\WebDriverExpectedCondition::textToBePresentInElement($this->_getWebDriverBy($selector), $text));
 }
Example #20
0
 /**
  * Waits for text to appear on the page for a specific amount of time.
  * Can also be passed a selector to search in.
  * If text does not appear, timeout exception is thrown.
  *
  * ``` php
  * <?php
  * $I->waitForText('foo', 30); // secs
  * $I->waitForText('foo', 30, '.title'); // secs
  * ?>
  * ```
  *
  * @param string $text
  * @param int $timeout seconds
  * @param null $selector
  * @throws \Exception
  * @internal param string $element
  */
 public function waitForText($text, $timeout = 10, $selector = null)
 {
     $condition = null;
     if (!$selector) {
         $condition = \WebDriverExpectedCondition::textToBePresentInElement(\WebDriverBy::xpath('//body'), $text);
     } else {
         if (Locator::isID($selector)) {
             $condition = \WebDriverExpectedCondition::textToBePresentInElement(\WebDriverBy::id(substr($selector, 1)), $text);
         }
         if (!$condition and Locator::isCSS($selector)) {
             $condition = \WebDriverExpectedCondition::textToBePresentInElement(\WebDriverBy::cssSelector($selector), $text);
         }
         if (Locator::isXPath($selector)) {
             $condition = \WebDriverExpectedCondition::textToBePresentInElement(\WebDriverBy::xpath($selector), $text);
         }
         if (!$condition) {
             throw new \Exception("Only CSS or XPath allowed");
         }
     }
     $this->webDriver->wait($timeout)->until($condition);
 }
 public function testShouldShowSavings()
 {
     reset_webservice();
     $this->set_api_key('PNG123');
     $this->upload_image(dirname(__FILE__) . '/../fixtures/input-example.png');
     self::$driver->get(wordpress('/wp-admin/options-media.php'));
     self::$driver->wait(2)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::cssSelector('#tiny-compress-savings p')));
     $elements = self::$driver->findElement(WebDriverBy::id('tiny-compress-savings'))->findElements(WebDriverBy::tagName('p'));
     $statuses = array_map('innerText', $elements);
     $this->assertContains('You have saved a total of 53.0 kB on images!', $statuses);
 }
 /**
  * @param $start_time
  *  The timestamp on the user ID we are modifying the program for
  * @param $time_change
  *  $time parameter passed to strtotime
  */
 public function adminChangeProgramVUD($start_time, $time_change)
 {
     $this->webDriver->get($this->url . '/admin/structure/entity-type/checklist/accredited');
     Automation::grabElementByCssSelector($this->webDriver, '.pager-last > a:nth-child(1)')->click();
     // Page to last page
     // And then all of this to wait for the list to refresh...
     $this->webDriver->wait(3, 500)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::cssSelector('.pager-first')));
     $link = $this->webDriver->findElement(WebDriverBy::linkText("Checklist Accredited | Webdriver Program {$start_time}"));
     $link->click();
     $edit_url = $this->webDriver->getCurrentURL() . '/edit';
     $this->webDriver->get($edit_url);
     $vud_box = Automation::grabElementByCssSelector($this->webDriver, '#edit-field-accreditation-valid-until-und-0-value-date');
     $vud = $vud_box->getAttribute('value');
     $vud_date = strtotime($vud);
     $minus1year = strtotime($time_change, $vud_date);
     $minus1year_text = date('M d Y', $minus1year);
     $vud_box->clear();
     $vud_box->sendKeys($minus1year_text);
     $submit = Automation::grabElementByCssSelector($this->webDriver, '#edit-submit');
     $submit->click();
 }
Example #23
0
 public function testBuildUpload()
 {
     $this->driver->get('http://localhost:80/builds/upload.php');
     $status = $this->driver->findElement(WebDriverBy::id("uploadStatus"));
     $this->assertContains("Upload a Build", $status->getText());
     $buildname = $this->driver->findElement(WebDriverBy::id("buildname"));
     $buildname->sendKeys("asdf");
     $filename = $this->driver->findElement(WebDriverBy::id("filename"));
     $filename->sendKeys("gioeunfa");
     $description = $this->driver->findElement(WebDriverBy::id("description"));
     $description->sendKeys("ghaseguiahgkareguhlgiuwf");
     $this->assertEquals("gioeunfa.bls", $filename->getAttribute("value"));
     $filename->sendKeys(KEYS::ENTER);
     $this->driver->wait(5, 250)->until(WebDriverExpectedCondition::textToBePresentInElement(WebDriverBy::id("uploadStatus"), "No file was selected to be uploaded"));
     $this->assertContains("No file was selected to be uploaded", $status->getText());
     $file = $this->driver->findElement(WebDriverBy::id("uploadfile"));
     $file->sendKeys(dirname(__DIR__) . "/res/some ramps.bls");
     $filename->sendKeys(KEYS::ENTER);
     $this->driver->wait(5, 250)->until(WebDriverExpectedCondition::not(WebDriverExpectedCondition::titleIs("Build Upload")));
 }
Example #24
0
 public static function grabElementByCssSelector(RemoteWebDriver $webDriver, $cssSelector)
 {
     $webDriver->wait(10, 1500)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::cssSelector($cssSelector)));
     $element = $webDriver->findElement(WebDriverBy::cssSelector($cssSelector));
     return $element;
 }
 public function __construct($apply)
 {
     parent::__construct($apply);
 }