* Adjust open url method.
This commit is contained in:
@@ -29,7 +29,7 @@ class createProductTester extends tester
|
||||
/* 提交表单。 */
|
||||
$this->login();
|
||||
$formPage = $this->formPage('product', 'create');
|
||||
$formPage->name->setValue($name);
|
||||
$formPage->dom->name->setValue($name);
|
||||
$formPage->submit();
|
||||
|
||||
$this->parseCurrentUrl();
|
||||
|
||||
+23
-107
@@ -1,68 +1,53 @@
|
||||
<?php
|
||||
class page
|
||||
{
|
||||
public $driver;
|
||||
public $webDriver;
|
||||
public $lang;
|
||||
public $xpathName;
|
||||
public $doms;
|
||||
public $xpath;
|
||||
public $timeout = 5;
|
||||
|
||||
public function __construct()
|
||||
public function __construct($webDriver)
|
||||
{
|
||||
global $driver, $lang;
|
||||
$this->driver = $driver;
|
||||
$this->lang = $lang;
|
||||
$this->doms = array(
|
||||
global $lang;
|
||||
$this->webDriver = $webDriver;
|
||||
$this->lang = $lang;
|
||||
$this->doms = array(
|
||||
'menuMoreNav' => '//*[@id="menuMoreNav"]/li[2]/a'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element of mainNav menu.
|
||||
* Open a app tab.
|
||||
*
|
||||
* @param string $app
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function mainNav($app)
|
||||
public function openAppTab($appTab)
|
||||
{
|
||||
$xpath = "//li[@data-app='$app']/a";
|
||||
$this->driver->waitElement($xpath, $this->timeout)->getElement($xpath);
|
||||
$xpath = "//li[@data-app='$appTab']/a";
|
||||
$this->webDriver->waitElement($xpath, $this->timeout)->getElement($xpath)->click();
|
||||
$this->webDriver->wait(1)->switchToIframe("appIframe-{$appTab}");
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element of navbar.
|
||||
* open a navbar.
|
||||
*
|
||||
* @param string $nav
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function navbar($nav)
|
||||
public function openNavbar($nav)
|
||||
{
|
||||
$xpath = "//a[@data-id='$nav']";
|
||||
$this->driver->waitElement($xpath, $this->timeout)->getElement($xpath);
|
||||
$this->webDriver->waitElement($xpath, $this->timeout)->getElement($xpath)->click();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get xpath of the zTable.
|
||||
*
|
||||
* @param string $colName
|
||||
* @param string $index
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function dTable($colName, $index)
|
||||
{
|
||||
$xpath = "//div[@class='dtable-cells-container']//[@data-col='$colName'][$index]";
|
||||
|
||||
return $xpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element of a button.
|
||||
*
|
||||
@@ -74,51 +59,11 @@ class page
|
||||
public function btn($value, $type = 'text')
|
||||
{
|
||||
$xpath = $type == 'text' ? "//*[text()='$value']" : $value;
|
||||
$this->driver->waitElement($xpath, $this->timeout)->getElement($xpath);
|
||||
$this->webDriver->waitElement($xpath, $this->timeout)->getElement($xpath);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the xpath of picker.
|
||||
*
|
||||
* @param string $value
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function picker($value)
|
||||
{
|
||||
$this->driver->picker($this->xpath, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the xpath of multiPicker.
|
||||
*
|
||||
* @param string $value
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function multiPicker($value)
|
||||
{
|
||||
$this->driver->multiPicker($this->xpath, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use datePicker in webDriver.
|
||||
*
|
||||
* @param string $value
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function datePicker($value)
|
||||
{
|
||||
$this->driver->datePicker($this->xpathName, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert incoming page elements to xpath.
|
||||
*
|
||||
@@ -128,6 +73,8 @@ class page
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
if($name == 'dom') return $this;
|
||||
|
||||
$this->xpathName = $name;
|
||||
if(isset($this->doms[$name]))
|
||||
{
|
||||
@@ -138,8 +85,7 @@ class page
|
||||
$xpath = $this->generateXPath($name);
|
||||
}
|
||||
|
||||
$this->xpath = $xpath;
|
||||
$this->driver->waitElement($xpath, $this->timeout)->getElement($xpath);
|
||||
$this->webDriver->waitElement($xpath, $this->timeout)->getElement($xpath);
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -156,21 +102,21 @@ class page
|
||||
|
||||
try
|
||||
{
|
||||
$this->driver->getElement($element);
|
||||
$this->webDriver->getElement($element);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
try
|
||||
{
|
||||
$element = '//*[@name="' . $name . '[]' . '"]';
|
||||
$this->driver->getElement($element);
|
||||
$this->webDriver->getElement($element);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$element = '//*[@id="' . $name . '"]';
|
||||
try
|
||||
{
|
||||
$this->driver->getElement($element);
|
||||
$this->webDriver->getElement($element);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
@@ -190,7 +136,7 @@ class page
|
||||
*/
|
||||
public function getFormTips()
|
||||
{
|
||||
$elements = $this->driver->getElementList('xpath://div[contains(@class, "form-tip")]');
|
||||
$elements = $this->webDriver->getElementList('xpath://div[contains(@class, "form-tip")]');
|
||||
|
||||
$tips = array();
|
||||
foreach($elements as $element)
|
||||
@@ -212,38 +158,8 @@ class page
|
||||
*/
|
||||
public function __call($method, $params = array())
|
||||
{
|
||||
if(method_exists($this->driver, $method)) return call_user_func_array(array($this->driver, $method), $params);
|
||||
if(method_exists($this->webDriver, $method)) return call_user_func_array(array($this->webDriver, $method), $params);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* open a mainMenu, navBar or URl.
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $type mainNav|navBar|switchToUrl
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function go($value, $type = 'switchToUrl')
|
||||
{
|
||||
if(in_array($type, array('mainNav', 'navBar')))
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->$type($value)->click();
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
$this->menuMoreNav->click();
|
||||
$this->mainNav($value)->click();
|
||||
}
|
||||
|
||||
$this->wait(1)->switchTo('appIframe-' . $value);
|
||||
}
|
||||
|
||||
if($type == 'switchToUrl') $this->$type($value, true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
+15
-11
@@ -30,7 +30,7 @@ include __DIR__ . '/result.class.php';
|
||||
|
||||
/* 初始化php-webdriver类 */
|
||||
include __DIR__ . '/webdriver/webdriver.class.php';
|
||||
$driver = new webdriver();
|
||||
$webdriver = new webdriver($config->uitest->chrome);
|
||||
|
||||
/* 初始化页面元素 */
|
||||
include 'page.class.php';
|
||||
@@ -66,8 +66,6 @@ function p($keys = '', $delimiter = ',')
|
||||
|
||||
if(empty($_result)) return print(implode("\n", array_fill(0, substr_count($keys, $delimiter) + 1, 0)) . "\n");
|
||||
|
||||
if(is_array($_result) && isset($_result['code']) && $_result['code'] == 'fail') return print((string) $_result['message'] . "\n");
|
||||
|
||||
/* Print $_result. */
|
||||
if($keys === '' && is_array($_result)) return print_r($_result) . "\n";
|
||||
|
||||
@@ -231,13 +229,15 @@ class tester
|
||||
public $page;
|
||||
public $config;
|
||||
public $result;
|
||||
public $cookieFile;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
global $config, $result;
|
||||
global $webdriver, $config, $result;
|
||||
$this->config = $config;
|
||||
$this->page = new Page();
|
||||
$this->page = new Page($webdriver);
|
||||
$this->result = $result;
|
||||
$this->cookieFile = CONFIG_ROOT . DS . 'cookie' . DS . 'cookie';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,22 +246,23 @@ class tester
|
||||
* @param string $account
|
||||
* @param string $password
|
||||
* @access public
|
||||
* @return void
|
||||
* @return object
|
||||
*/
|
||||
public function login($account = '', $password = '')
|
||||
{
|
||||
if(!$account) $account = $this->config->uitest->defaultAccount;
|
||||
if(!$password) $password = $this->config->uitest->defaultPassword;
|
||||
$webRoot = rtrim($this->config->uitest->webRoot, '/') . '/';
|
||||
|
||||
$this->page->deleteCookie();
|
||||
|
||||
$this->page->get('');
|
||||
$this->page->openURL($webRoot);
|
||||
$this->page->getErrors();
|
||||
$this->page->account->setValue($account);
|
||||
$this->page->password->setValue($password);
|
||||
$this->page->submit->click();
|
||||
|
||||
$this->page->getCookie();
|
||||
$this->page->saveCookie($this->cookieFile);
|
||||
|
||||
return $this->page;
|
||||
}
|
||||
@@ -281,6 +282,8 @@ class tester
|
||||
if(!$module || !$method) return;
|
||||
$this->result->module = $module;
|
||||
$this->result->method = $method;
|
||||
$webRoot = rtrim($this->config->uitest->webRoot, '/') . '/';
|
||||
$cookies = json_decode(file_get_contents($this->cookieFile), true);
|
||||
|
||||
if($this->config->requestType == 'GET')
|
||||
{
|
||||
@@ -294,10 +297,11 @@ class tester
|
||||
$url .= ".html";
|
||||
}
|
||||
|
||||
$this->page->go($url); // 跳转到地址
|
||||
$this->page->openURL($webRoot)->deleteCookie();
|
||||
foreach($cookies as $cookie) if($cookie["name"] == "zentaosid") $this->page->addCookie($cookie);
|
||||
|
||||
$appIframeID = $iframeID ? $iframeID : "appIframe-{$module}";
|
||||
$this->page->wait(1);
|
||||
$this->page->getErrors($appIframeID);
|
||||
$this->page->wait(1)->getErrors($appIframeID);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -161,6 +161,19 @@ class webdriver
|
||||
return $isSave ? $cookie : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a cookie.
|
||||
*
|
||||
* @param array $cookie
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function addCookie($cookie)
|
||||
{
|
||||
$this->driver->manage()->addCookie($cookie);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete cookies in page.
|
||||
*
|
||||
@@ -199,11 +212,7 @@ class webdriver
|
||||
}
|
||||
$this->driver->get($this->config->uitest->webRoot);
|
||||
$this->driver->manage()->deleteAllCookies();
|
||||
foreach($cookies as $cookie)
|
||||
{
|
||||
if($cookie["name"] == "zentaosid") $this->driver->manage()->addCookie($cookie);
|
||||
if($cookie["name"] == "quchengsid") $this->driver->manage()->addCookie($cookie);
|
||||
}
|
||||
foreach($cookies as $cookie) if($cookie["name"] == "zentaosid") $this->driver->manage()->addCookie($cookie);
|
||||
$this->driver->get($url);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user