示例#1
0
 public function testDemo2()
 {
     //click button/get alert text
     $this->_driver->get($this->_testUrl);
     $this->_driver->findElement(By::id("btnAlert"))->click();
     $alert = $this->_driver->switchTo()->alert();
     $this->assertEquals("Here is the alert", $alert->getText());
     $alert->accept();
     //get main window handle
     $mainWindowHandle = $this->_driver->getWindowHandle();
     //open popup window / handle its elements
     $this->_driver->findElement(By::id("btnPopUp1"))->click();
     $this->_driver->switchTo()->window("popup1");
     $webElement = $this->_driver->waitForElementUntilIsPresent(By::id("txt1"));
     $webElement->sendKeys("test window");
     $this->assertEquals("test window", $webElement->getAttribute("value"));
     $this->_driver->close();
     $this->_driver->switchTo()->window($mainWindowHandle);
     //get iframe / handle its elements
     $this->_driver->switchTo()->frame("iframe1");
     $webElement = $this->_driver->waitForElementUntilIsPresent(By::id("txt1"));
     $webElement->sendKeys("test iframe");
     $this->assertEquals("test iframe", $webElement->getAttribute("value"));
     $this->_driver->switchTo()->window($mainWindowHandle);
     //wait for element to be present
     $this->_driver->findElement(By::id("btnAppendDiv"))->click();
     $wait = new WebDriverWait(8);
     $label = $wait->until($this->_driver, "findElement", array(By::id("dDiv1-0"), true));
     $this->assertEquals("Some content", $label->getText());
     sleep(5);
 }
 public function testUntilShouldWaitShouldThrowException()
 {
     $this->setExpectedException('Nearsoft\\SeleniumClient\\Exceptions\\WebDriverWaitTimeout');
     $this->_driver->findElement(By::id("btnAppendDiv"))->click();
     $wait = new WebDriverWait(3);
     $label = $wait->until($this->_driver, "findElement", array(By::id("dDiv1-0"), true));
 }
 public function testGetAlertShouldSendKeysToAlert()
 {
     $this->_driver->findElement(By::id("btnPrompt"))->click();
     $this->_alert->sendKeys("alert text");
     $this->_alert->accept();
     $alertText = $this->_alert->getText();
     $this->assertEquals("alert text", $alertText);
 }
 public function testSelectByPartialTextShouldSelect()
 {
     $select = new SelectElement($this->_driver->findElement(By::id("sel1")));
     $select->selectByPartialText("Red");
     $this->assertTrue($select->getElement()->findElement(By::xPath("option[@value = 2]"))->isSelected());
     $select = new SelectElement($this->_driver->findElement(By::id("sel2")));
     $select->selectByPartialText("peppers");
     $this->assertTrue($select->getElement()->findElement(By::xPath("option[@value = 'greenpeppers']"))->isSelected());
 }
 public function testRefreshShouldRefreshPageAndEmptyElement()
 {
     $webElement = $this->_driver->findElement(By::id("txt1"));
     $webElement->sendKeys("9999");
     $navigation = $this->_driver->navigate();
     $navigation->refresh();
     $webElement = $this->_driver->findElement(By::id("txt1"));
     $this->assertEquals("", $webElement->getAttribute("value"));
 }
 public function testImplicitWait()
 {
     $this->_driver->findElement(By::id("btnAppendDiv"))->click();
     $timeouts = $this->_driver->manage()->timeouts();
     $timeouts->implicitWait(5000);
     $webElement = $this->_driver->findElement(By::id("dDiv1-0"));
     // This takes 5 seconds to be present
     $this->assertInstanceOf('Nearsoft\\SeleniumClient\\WebElement', $webElement);
 }
示例#7
0
 public function testDemo1()
 {
     //get url
     $this->_driver->get($this->_testUrl);
     sleep(4);
     //access text input
     $webElement = $this->_driver->findElement(By::id("txt1"));
     $webElement->clear();
     $webElement->sendKeys("Text sent 1");
     $this->assertEquals("Text sent 1", $webElement->getAttribute("value"));
     $webElement = $this->_driver->findElement(By::id("txt2"));
     $webElement->clear();
     $webElement->sendKeys("Text sent 2");
     $this->assertEquals("Text sent 2", $webElement->getAttribute("value"));
     //access listbox
     $selectElement = new SelectElement($this->_driver->findElement(By::id("sel1")));
     $selectElement->selectByValue("4");
     $this->assertTrue($selectElement->getElement()->findElement(By::xPath(".//option[@value = 4]"))->isSelected());
     //access checkbox
     $webElement = $this->_driver->findElement(By::cssSelector("html body table tbody tr td fieldset form p input#chk3"));
     $webElement->click();
     $this->assertTrue($webElement->isSelected());
     //access radio
     $webElement = $this->_driver->findElement(By::id("rd3"));
     $webElement->click();
     $this->assertTrue($webElement->isSelected());
     //access button
     $webElement = $this->_driver->findElement(By::id("btnSubmit"));
     $webElement->click();
     //access h2
     $webElement = $this->_driver->findElement(By::cssSelector("html body h2#h2FormReceptor"));
     $this->assertEquals("Form receptor", $webElement->getText());
     //navigation
     $this->_driver->get('http://www.nearsoft.com');
     $this->_driver->navigate()->refresh();
     $this->_driver->navigate()->back();
     $this->_driver->navigate()->forward();
     sleep(5);
 }
 public function testSendKeysShouldRetrieveHebrewText()
 {
     $textarea1 = $this->_driver->findElement(By::id("txtArea1"));
     $textarea1->sendKeys("יאיר 34557");
     $this->assertEquals("יאיר 34557", $textarea1->getAttribute("value"));
 }
 /**
  * Gets elements within current page
  * @param By   $locator
  * @param bool $polling
  * @param int  $elementId
  * @throws Exceptions\InvalidSelector
  * @return Nearsoft\SeleniumClient\WebElement[]
  */
 public function findElements(By $locator, $polling = false, $elementId = -1)
 {
     if (strpos($locator->getStrategy(), 'js selector ') === 0) {
         $function = substr($locator->getStrategy(), 12);
         $script = "return typeof window.{$function};";
         $valid = $this->executeScript($script) == 'function';
         $selector = addslashes($locator->getSelectorValue());
         if (!$valid) {
             throw new Exceptions\InvalidSelector('The selectorElement is not defined');
         }
         if ($elementId >= 0) {
             // todo refactor child selection strategy to separate classes
             if (strpos($function, 'document.') === 0) {
                 // assume child.$function($selector)
                 $function = substr($function, 9);
                 $script = sprintf('return arguments[0].%s("%s")', $function, $selector);
             } else {
                 // assume $function($selector, child)
                 $script = sprintf('return %s("%s", arguments[0])', $function, $selector);
             }
             $args = array(array('ELEMENT' => $elementId));
         } else {
             $script = sprintf('return %s("%s")', $function, $selector);
             $args = array();
         }
         $params = array('script' => $script, 'args' => $args);
         $command = new Commands\Command($this, 'execute_script', $params);
         $results = $command->execute();
     } else {
         $params = array('using' => $locator->getStrategy(), 'value' => $locator->getSelectorValue());
         if ($elementId >= 0) {
             $command = new Commands\Command($this, 'elements_in_element', $params, array('element_id' => $elementId));
         } else {
             $command = new Commands\Command($this, 'elements', $params);
         }
         $results = $command->execute();
     }
     $webElements = array();
     if (isset($results['value']) && is_array($results['value'])) {
         foreach ($results['value'] as $element) {
             $webElements[] = new WebElement($this, is_array($element) ? $element['ELEMENT'] : $element);
         }
     }
     return $webElements ?: null;
 }
 public function testAlertShouldGetAlertInstance()
 {
     $this->_driver->findElement(By::id("btnAlert"))->click();
     $alert = $this->_targetLocator->alert();
     $this->assertTrue($alert instanceof Alert);
 }
 public function testCloseWindowShouldClose()
 {
     $this->_driver->findElement(By::id("btnPopUp1"))->click();
     $this->_driver->switchTo()->window("popup1");
     $this->_driver->close();
     $this->setExpectedException('Nearsoft\\SeleniumClient\\Exceptions\\NoSuchWindow');
     $this->_driver->getCurrentUrl();
 }
示例#12
0
文件: Cardo.php 项目: velber/cardo
 private function findSaled()
 {
     $webProdano = $this->driver->findElements(By::xPath('//span[@class="prodano"]'));
     if (count($webProdano) > 0) {
         return true;
     } else {
         return false;
     }
 }