Selenium在测试时会打开一个奇怪的URL

时间:2015-12-18 16:23:13

标签: selenium phpunit

当我使用Selenium开始测试时,Firefox会出现“找不到文件”错误,因为该网址为:

  

铬://src/content/RemoteRunner.html的sessionId = b147cdb005864b69b5fbe8cbb74639fb&安培;多窗口=真安培;的baseUrl = HTTP%3A%2F%2Flocalhost&安培; debugMode =假安培; driverUrl = http://localhost:4444/selenium-server/driver/

...这与我配置它打开(localhost / admin)

的完全不同

为什么首先打开此网址,使用chrome:在其中,当我甚至没有Chrome时?

Selenium log:

18:21:23.580 INFO - Launching a standalone Selenium Server
18:21:23.616 INFO - Java: Oracle Corporation 24.91-b01
18:21:23.616 INFO - OS: Linux 3.19.0-32-generic amd64
18:21:23.634 INFO - v2.48.0, with Core v2.48.0. Built from revision 41bccdd
18:21:23.714 INFO - Driver provider org.openqa.selenium.ie.InternetExplorerDriver registration is skipped:
registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet        explorer, version=}] does not match the current platform LINUX
18:21:23.714 INFO - Driver provider org.openqa.selenium.edge.EdgeDriver registration is skipped:
registration capabilities Capabilities [{platform=WINDOWS, browserName=MicrosoftEdge, version=}] does not       match the current platform LINUX
18:21:23.714 INFO - Driver class not found: com.opera.core.systems.OperaDriver
18:21:23.715 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
18:21:23.796 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
18:21:23.796 INFO - Selenium Server is up and running
18:21:28.215 INFO - Command request: getNewBrowserSession[firefox, http://localhost] on session null
18:21:28.217 INFO - creating new remote session
18:21:28.238 WARN - Caution: '/usr/bin/firefox': file is a script file, not a real executable.  The browser         environment is no longer fully under RC control
18:21:28.240 INFO - Allocated session 48b6b368a2f74e4aac71f8e8fe063c50 for http://localhost, launching...
jar:file:/home/davion100/Documents/selenium-server-standalone-2.48.2.jar!/customProfileDirCUSTFFCHROME
18:21:28.427 INFO - Launching Firefox...

测试:

<?php
use PHPUnit\Extensions\SeleniumTestCase;
use ApplicationTest\Bootstrap;
require_once ("Config.php");

class AdminSelectionComponentsTest extends PHPUnit_Extensions_SeleniumTestCase
{
    protected $captureScreenshotOnFailure = true;
    protected $screenshotPath = "";
    protected $screenshotUrl = "http://*******/screenshots";
    protected $path = PATH;
    protected $componentName = "Test Component";
    protected $componentNameEdited = "Edited Test Component";
    protected $componentDescription = "This is a test component";
    protected $contextTitle = "Test Context";
    protected $contextTitleEdited = "Edited Test Context";
    protected $contextQuestion = "Is this a Test Question?";
    protected $contextQuestionEdited = "Is this an Edited Test Question?";
    protected $contextAnswer = "Yes";
    protected $componentDefaultDuration = 60;
    private static $oldComponent;
    private static $newComponent;
    private static $oldContext;
    private static $newContext;
    private static $oldQuestion;
    private static $newQuestion;

    /**
     * Set up
     * @see PHPUnit_Framework_TestCase::setUp()
     * @return void
     */
    protected function setUp()
    {
    $this->screenshotPath = __DIR__ . "/FailedTestsScreenshots";
    if(! file_exists($this->screenshotPath))
    {
        mkdir($this->screenshotPath);
    }
    $this->setBrowser(BROWSER);
    $this->setBrowserUrl($this->path);
    }

    /**
     * Test components info.
     * @return void
     */
    public function testComponentsInfo()
    {
    $this->open("/admin");
    $this->type("name=username", "admin");
    $this->type("name=password", "admin");
    $this->click("id=submitbutton");
    $this->waitForPageToLoad("30000");
    $this->click("css=a.dropdown-toggle");
    $this->click("css=a[href='/admin/index/setsystem/system/5']");
    $this->waitForPageToLoad("30000");
    $this->click("link=Components");
    $this->waitForPageToLoad("30000");
    $this->assertEquals("Components", $this->getText("css=h1"));
    $this->assertTrue($this->isElementPresent("css=table#dt_basic"));
    $this->click("css=a.btn.blue");
    $this->waitForPageToLoad("30000");
    $this->assertEquals("Name", $this->getText("css=td.definition"));
    $this->assertEquals("DefaultDuration", $this->getText("css=td.definition:nth(1)"));
    $this->assertEquals("Archived", $this->getText("css=td.definition:nth(2)"));
    $this->assertEquals("Description", $this->getText("css=td.definition:nth(3)"));
    $this->click("link=back to the list of component objects");
    $this->waitForPageToLoad("30000");
    $this->assertEquals("Components", $this->getText("css=h1"));
    $this->assertTrue($this->isElementPresent("css=table#dt_basic"));
    }

    /**
     * Test adding component.
     * @return void
     */
    public function testComponentsAdd()
    {
    $components = iterator_to_array(Bootstrap::getServiceManager()->get("ComponentTable")->fetchAll(false, null, "id", null, null));
    self::$oldComponent = end($components);
    $this->open("/admin");
    $this->type("name=username", "admin");
    $this->type("name=password", "admin");
    $this->click("id=submitbutton");
    $this->waitForPageToLoad("30000");
    $this->click("css=a.dropdown-toggle");
    $this->click("css=a[href='/admin/index/setsystem/system/5']");
    $this->waitForPageToLoad("30000");
    $this->click("link=Components");
    $this->waitForPageToLoad("30000");
    $this->click("css=a[href='/admin/component/add']");
    $this->waitForPageToLoad("30000");
    $this->type("name=name", $this->componentName);
    $this->type("name=defaultDuration", $this->componentDefaultDuration);
    $this->type("name=description", $this->componentDescription);
    $this->click("id=submitbutton");
    $this->waitForPageToLoad("30000");
    $componentsNew = iterator_to_array(Bootstrap::getServiceManager()->get("ComponentTable")->fetchAll(false, null, "id", null, null));
    self::$newComponent = end($componentsNew);
    $this->assertTrue(self::$oldComponent->id < self::$newComponent->id);
    $this->assertTrue(self::$newComponent->name == $this->isElementPresent("css=td:contains('$this->componentName')"));
    }

    /**
     * Test editing component.
     * @return void
     */
    public function testComponentEdit()
    {
    $this->assertTrue(self::$oldComponent->id < self::$newComponent->id);
    $this->open("/admin");
    $this->type("name=username", "admin");
    $this->type("name=password", "admin");
    $this->click("id=submitbutton");
    $this->waitForPageToLoad("30000");
    $this->click("css=a.dropdown-toggle");
    $this->click("css=a[href='/admin/index/setsystem/system/5']");
    $this->waitForPageToLoad("30000");
    $this->open("/admin/component/modify/id/" . self::$newComponent->id);
    $this->waitForPageToLoad("30000");
    $this->type("name=name", $this->componentNameEdited);
    $this->click("id=submitbutton");
    $this->waitForPageToLoad("30000");
    $componentsNew = iterator_to_array(Bootstrap::getServiceManager()->get("ComponentTable")->fetchAll(false, null, "id", null, null));
    self::$newComponent = end($componentsNew);
    $this->assertTrue(self::$newComponent->name == $this->isElementPresent("css=td:contains('$this->componentNameEdited')"));
    }

    /**
     * Test adding context.
     * @return void
     */
    public function testContextAdd()
    {
    $this->assertTrue(self::$oldComponent->id < self::$newComponent->id);
    $contexts = iterator_to_array(Bootstrap::getServiceManager()->get("ContextTable")->fetchAll(false, null, "id", null, null));
    self::$oldContext = end($contexts);
    $this->open("/admin");
    $this->type("name=username", "admin");
    $this->type("name=password", "admin");
    $this->click("id=submitbutton");
    $this->waitForPageToLoad("30000");
    $this->click("css=a.dropdown-toggle");
    $this->click("css=a[href='/admin/index/setsystem/system/5']");
    $this->waitForPageToLoad("30000");
    $this->open("/admin/context/index/component/" . self::$newComponent->id);
    $this->waitForPageToLoad("30000");
    $this->click("css=a span#add");
    $this->waitForPageToLoad("30000");
    $this->type("name=title", $this->contextTitle);
    $this->click("css=#submitbutton");
    $this->waitForPageToLoad("30000");
    $contextsNew = iterator_to_array(Bootstrap::getServiceManager()->get("ContextTable")->fetchAll(false, null, "id", null, null));
    self::$newContext = end($contextsNew);
    $this->assertTrue(self::$oldContext->id < self::$newContext->id);
    $this->assertTrue(self::$newContext->title == $this->isElementPresent("css=td:contains('$this->contextTitle')"));
    }

    /**
     * Test editing context.
     * @return void
     */
    public function testContextEdit()
    {
    $this->assertTrue(self::$oldComponent->id < self::$newComponent->id);
    $this->assertTrue(self::$oldContext->id < self::$newContext->id);
    $this->open("/admin");
    $this->type("name=username", "admin");
    $this->type("name=password", "admin");
    $this->click("id=submitbutton");
    $this->waitForPageToLoad("30000");
    $this->click("css=a.dropdown-toggle");
    $this->click("css=a[href='/admin/index/setsystem/system/5']");
    $this->waitForPageToLoad("30000");
    $this->open($this->path."/admin/context/modify/id/" . self::$newContext->id . "/component/" . self::$newComponent->id);
    $this->waitForPageToLoad("30000");
    $this->type("name=title", $this->contextTitleEdited);
    $this->click("css=#submitbutton");
    $this->waitForPageToLoad("30000");
    $contextsNew = iterator_to_array(Bootstrap::getServiceManager()->get("ContextTable")->fetchAll(false, null, "id", null, null));
    self::$newContext = end($contextsNew);
    $this->assertTrue(self::$newContext->title == $this->isElementPresent("css=td:contains('$this->contextTitleEdited')"));
    }

    /**
     * Test Adding context question.
     * @return void
     */
    public function testContextQuestionAdd()
    {
    $this->assertTrue(self::$oldComponent->id < self::$newComponent->id);
    $this->assertTrue(self::$oldContext->id < self::$newContext->id);
    $questions = iterator_to_array(Bootstrap::getServiceManager()->get("ContextQuestionTable")->fetchAll(false, null, "id", null, null));
    self::$oldQuestion = end($questions);
    $this->open("/admin");
    $this->type("name=username", "admin");
    $this->type("name=password", "admin");
    $this->click("id=submitbutton");
    $this->waitForPageToLoad("30000");
    $this->click("css=a.dropdown-toggle");
    $this->click("css=a[href='/admin/index/setsystem/system/5']");
    $this->waitForPageToLoad("30000");
    $this->open("/admin/contextquestion/index/context/" . self::$newContext->id . "/component/" . self::$newComponent->id);
    $this->waitForPageToLoad("30000");
    $this->click(
            "css=a[href='/admin/contextquestion/add/component/" . self::$newComponent->id . "/context/" . self::$newContext->id . "']");
    $this->waitForPageToLoad("30000");
    $this->type("name=question", $this->contextQuestion);
    $this->runScript("CKEDITOR.instances['question'].setData('<p>$this->contextQuestion</p>');");
    $this->click("css=#submitbutton");
    $this->waitForPageToLoad("30000");
    $questionsNew = iterator_to_array(
            Bootstrap::getServiceManager()->get("ContextQuestionTable")->fetchAll(false, null, "id", null, null));
    self::$newQuestion = end($questionsNew);
    $this->assertTrue(self::$oldQuestion->id < self::$newQuestion->id);
    $this->assertTrue(self::$newQuestion->question == $this->isElementPresent("css=td:contains('$this->contextQuestion')"));
    }

    /**
     * Test editing context question.
     * @return void
     */
    public function testContextQuestionEdit()
    {
    $this->assertTrue(self::$oldComponent->id < self::$newComponent->id);
    $this->assertTrue(self::$oldContext->id < self::$newContext->id);
    $this->assertTrue(self::$oldQuestion->id < self::$newQuestion->id);
    $this->open("/admin");
    $this->type("name=username", "admin");
    $this->type("name=password", "admin");
    $this->click("id=submitbutton");
    $this->waitForPageToLoad("30000");
    $this->click("css=a.dropdown-toggle");
    $this->click("css=a[href='/admin/index/setsystem/system/5']");
    $this->waitForPageToLoad("30000");
    $this->click("link=Components");
    $this->waitForPageToLoad("30000");
    $this->open(
            "/admin/contextquestion/modify/id/" . self::$newQuestion->id . "/component/" . self::$newComponent->id . "/context/" .
                     self::$newContext->id);
    $this->waitForPageToLoad("30000");
    $this->select("name=type", "label=OPENQUESTION");
    $this->click("css=#submitbutton");
    $this->waitForPageToLoad("30000");
    $questionsNew = iterator_to_array(
            Bootstrap::getServiceManager()->get("ContextQuestionTable")->fetchAll(false, null, "id", null, null));
    self::$newQuestion = end($questionsNew);
    $this->assertTrue(self::$newQuestion->type == 1);
    }

    /**
     * Test deleting all.
     * @return void
     */
    public function testDeleteAll()
    {
    $this->assertTrue(self::$oldComponent->id < self::$newComponent->id);
    $this->assertTrue(self::$oldContext->id < self::$newContext->id);
    $this->assertTrue(self::$oldQuestion->id < self::$newQuestion->id);
    $this->open("/admin");
    $this->type("name=username", "admin");
    $this->type("name=password", "admin");
    $this->click("id=submitbutton");
    $this->waitForPageToLoad("30000");
    $this->click("css=a.dropdown-toggle");
    $this->click("css=a[href='/admin/index/setsystem/system/5']");
    $this->waitForPageToLoad("30000");
    $this->click("link=Components");
    $this->waitForPageToLoad("30000");
    $this->open("/admin/component/delete/id/" . self::$newComponent->id);
    $this->waitForPageToLoad("30000");
    $componentsNew = iterator_to_array(Bootstrap::getServiceManager()->get("ComponentTable")->fetchAll(false, null, "id", null, null));
    $contextsNew = iterator_to_array(Bootstrap::getServiceManager()->get("ContextTable")->fetchAll(false, null, "id", null, null));
    $questionsNew = iterator_to_array(
            Bootstrap::getServiceManager()->get("ContextQuestionTable")->fetchAll(false, null, "id", null, null));
    self::$newComponent = end($componentsNew);
    self::$newContext = end($contextsNew);
    self::$newQuestion = end($questionsNew);
    $this->assertTrue(self::$oldComponent->id == self::$newComponent->id);
    $this->assertTrue(self::$oldContext->id == self::$newContext->id);
    $this->assertTrue(self::$oldQuestion->id == self::$newQuestion->id);
    }
}

0 个答案:

没有答案