GVKun编程网logo

在Selenium扩展中使用glob到PHPUnit来识别元素(selenium 识别)

8

关于在Selenium扩展中使用glob到PHPUnit来识别元素和selenium识别的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于c#–是否可以在不安装SeleniumServer的

关于在Selenium扩展中使用glob到PHPUnit来识别元素selenium 识别的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?、opensuse13.1 下 phpunit+selenium、PHPUnit Selenium Server – 更好/自定义错误处理?、PHPUnit selenium不支持sendKeys吗?等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

在Selenium扩展中使用glob到PHPUnit来识别元素(selenium 识别)

在Selenium扩展中使用glob到PHPUnit来识别元素(selenium 识别)

我正在使用Selenium扩展在 PHPUnit中编写Selenium测试用例.在测试中,我断言页面上存在某个链接.

例如,假设我想声明页面中存在以下链接:

<a href="http://www.stackoverflow.com">click here to enter stackoverflow</a>

为了断言链接存在,我需要识别它.通常我们使用它们的锚文本来识别链接:assertElementPresent(“link = click here to enter stackoverflow”).

我不想使用其整个锚文本来识别链接,而只是锚文本包含的子字符串“stackoverflow”.我可以使用glob和star运算符来执行此操作:assertElementPresent(“link = glob:* stackoverflow *”)

这在selenium IDE上非常有效,但是当在PHPUnit中编写等效代码时,断言失败了.这是PHPUnit中的等效代码行:

$this->assertTrue(isElementPresent("link=glob:*stackoverflow*"));

上面的断言失败,因为没有标识元素link = glob:* stackoverflow *.应该标识该元素,因为页面上存在一个链接,其锚文本包含字符串“stackoverflow”.

我的问题比我给出的简单示例更通用:我如何使用glob来识别Selenium扩展中的元素到PHPUnit?

解决方法

我们在所有Selenium测试用例中使用XPath表达式,但我没有参与编写它们,也没有调查其他选项.如果你找不到让glob工作的方法,你总是可以依靠这个:

self::assertTrue($this->isElementPresent("//a[contains(.,'stackoverflow')]"));

c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?

c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?

我之前使用IWebDriver控制IE进行测试.但是IWebDriver和IWebElement支持的方法非常有限.我发现属于Selenium命名空间的ISelenium / DefaultSelenium非常有用.如何在不安装Selenium Server的情况下使用它们来控制IE?

这是DefaultSelenium的构造函数:

ISelenium sele = new DefaultSelenium(**serveraddr**,**serverport**,browser,url2test);
sele.Start();
sele.open();
...

似乎我必须在创建ISelenium对象之前安装Selenium Server.

我的情况是,我正在尝试使用C#Selenium构建一个.exe应用程序,它可以在不同的PC上运行,并且不可能在所有PC上安装Selenium Server(你永远不知道哪个是下一个运行应用程序).

有没有人知道如何在不安装服务器的情况下使用ISelenium / DefaultSelenium?
谢谢!

解决方法

在不使用RC Server的情况下,Java中有一些解决方案:

1)对于selenium浏览器启动:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setbrowserName("safari");
CommandExecutor executor = new SeleneseCommandExecutor(new URL("http://localhost:4444/"),new URL("http://www.google.com/"),capabilities);
WebDriver driver = new RemoteWebDriver(executor,capabilities);

2)对于selenium命令:

// You may use any WebDriver implementation. Firefox is used here as an example
WebDriver driver = new FirefoxDriver();

// A "base url",used by selenium to resolve relative URLs
 String baseUrl = "http://www.google.com";

// Create the Selenium implementation
Selenium selenium = new WebDriverBackedSelenium(driver,baseUrl);

// Perform actions with selenium
selenium.open("http://www.google.com");
selenium.type("name=q","cheese");
selenium.click("name=btnG");

// Get the underlying WebDriver implementation back. This will refer to the
// same WebDriver instance as the "driver" variable above.
WebDriver driverInstance = ((WebDriverBackedSelenium) selenium).getWrappedDriver();

//Finally,close the browser. Call stop on the WebDriverBackedSelenium instance
//instead of calling driver.quit(). Otherwise,the JVM will continue running after
//the browser has been closed.
selenium.stop();

描述于此:http://seleniumhq.org/docs/03_webdriver.html

谷歌在C#中有类似的东西.没有其他方法可以实现这一目标.

opensuse13.1 下 phpunit+selenium

opensuse13.1 下 phpunit+selenium


正在学习 yii 框架,在编写 php 代码的时候,要用到单元测试。之前只听说单元测试,没怎么了解过,这次要用到了。在 yii 框架中使用 phpUnit 进行单元测试真的很方便。从 Yii1.1 版本起,Yii 已经紧密结合 phpUnit 和 selenium remote control 测试框架。

这是 yiic webapp 自动生成的 /protected/tests/ 目录,,我们将测试文件主要放到这个目录:fixtures , functional,unit。

一。安装 PHPUnit

(1)在命令行:


$>sudo pear channel-discover pear.phpunit.de


$>sudo pear install phpunit/PHPUnit



这是在 opensuse13.1 终端上所得到实验步骤,可能您的配置略有不同。详细安装过程请参考 http://phpunit.de/manual/3.7/en/installation.html

(2)opensuse13.1 Yast2

打开 yast2 出入 phpunit 勾选相应的选项。然后也可以成功安装。


二。安装 selenium

除了 phpunit,selem remote control server 为是了运行测试功能所需要的,安装 selenium 非常简单。

[1] . 从 http://code.google.com/p/selenium/downloads/list    下载 Selenium RC 的 zip 文件

[2] . 解压下载的 zip 文件到你的系统中。

运行这个服务时也很简单:

在 shell 下:

$>java -jar  selenium-server-standalone-2.37.0.jar


至此 phpUnit 安装已经搞定,用上面的方法开启 Selenium 服务

但是当我在 /protected/tests/> phpunit functional/SiteTest.php 时产生了错误。

Warning: include(): Failed opening ‘PHPUnit_Extensions_SeleniumTestCase_Driver.php 

查找资料以后在 shell 下面输入:

pear upgrade -f phpunit/phpunit_selenium

php 需要开启 curl

然后从新测试看到了如下的结果





PHPUnit Selenium Server – 更好/自定义错误处理?

PHPUnit Selenium Server – 更好/自定义错误处理?

我有没有办法让 PHPUnit在出错后继续?例如,我有一个大型测试套件(400个步骤),我宁愿如果说,找不到元素,它也不会阻止我的脚本继续运行.

解决方法

有一种更好的方法可以做到这一点.您可以重载一个方法:runtest(),而不是重载每个断言*()方法.它适用于每个断言,并且可以捕获异常:

abstract class AMyTestCase extends PHPUnit_Framework_TestCase
{
    public function runtest()
    {
        try {
            parent::runtest();
        }
        catch ( MyCustomException $Exc ) {
            // will continue tests
        }
        catch ( Exception $Exc ) {
            if ( false === strpos($Exc->getMessage(),'element not found') ) {
                // rethrow:
                throw $Exc;
            }
            // will also continue
        }
    }
}

PHPUnit selenium不支持sendKeys吗?

PHPUnit selenium不支持sendKeys吗?

我在Selenium IDE上使用sendKeys命令编写测试,这很好.但是当我更改为 PHPUnit Selenium时,我收到的错误是Method sendKeys未定义,所以我想知道PHPUnit-Selenium不支持或者我需要添加方法?如果答案是我需要添加senKeys方法,如果是这样,让我知道如何添加senKeys方法.

解决方法

我无法想象这一段时间……诀窍是它不是叫sendKeys而你在PHPUnit中不使用{ENTER}和Selenium.这些不是您正在寻找的功能!

而是,单击要键入的元素,然后使用键功能,如下所示:

$this->byXpath('//*[@id="theOnetoTypeIn"]')->click();
$this->keys('some keys to type'.Keys::ENTER);

确保在页面顶部还包含Keys类:

use PHPUnit_Extensions_Selenium2TestCase_Keys as Keys;

支持的密钥可在此处找到:https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value

我读到SendKeys的支持与JSON线框相同,所以我想象常量与它们在链接中的名称相同……但是我还想象所有的函数名都是一样的我们在这里.

关于在Selenium扩展中使用glob到PHPUnit来识别元素selenium 识别的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?、opensuse13.1 下 phpunit+selenium、PHPUnit Selenium Server – 更好/自定义错误处理?、PHPUnit selenium不支持sendKeys吗?等相关内容,可以在本站寻找。

本文标签: