duanliaoyin3171 2015-10-08 20:22
浏览 58

如何在laravel 5.1中使用Codeception打开Firefox? 或者如何在laravel 5上使用SPA进行验收测试?

I'm trying to create acceptance tests to work with reactJS. I first got Codeception running fine then added react. Thats when I noticed that codeception doesn't have JS enabled. I've tried adding phantomJS: same problem. Since I can't debug phantomJS, I decided to try selenium so I can see it run in firefox. I've been working on this for days and Codeception refuses to open firefox like a normal selenium test.

Things your gonna ask: - Yes, I run codecept build after every change. - Yes I have java -jar selenium-server-standalone-2.48.0.jar running. Though that doesn't matter. There is no difference in the test whether I have it running or not. - Yes I've tried $I->waitForElement('#whatever'). After like 20 seconds it dies. - No, I have to use laravel

Here's my configuration:

acceptance.suite.yml

class_name: AcceptanceTester
modules:
    enabled:
        - WebDriver:
            url: 'http://eagle.app/'
            browser: firefox #This does nothing. I literally changed it to `fart` and it didn't error. just same failed tests due to no JS
            window_size: 1024x768
            capabilities:
                webStorageEnabled: true
                javascriptEnabled: true
                firefox_binary: /Applications/Firefox.app
        - \Helper\Acceptance

/tests/acceptance/AuthCest.php

<?php
//use \AcceptanceTester;

class AuthCest
{
    public function _before(AcceptanceTester $I)
    {
    }

    public function _after(AcceptanceTester $I)
    {
    }

    // tests
    public function register(AcceptanceTester $I)
    {
        // This should open firefox/selenium
        $I->executeInSelenium(function (Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
            $handles=$webdriver->getWindowHandles();
            $last_window = end($handles);
            $webdriver->switchTo()->window($last_window);
        });

        // This is my original test. I realize its not in executeInSelenium()
        // but I'm just showing you what works in non-SPA laravel apps (which doesn't work for me)
        $I->switchToWindow();
        $I->am('an anonymous user');
        $I->wantTo('Register');
        $I->amOnPage('/');
        $I->wait(1);
        $I->see('Laravel 5'); #this is where it dies with react
        $I->click('REGISTER');
        $I->fillField(['name' => 'name'], 'testuser');
        $I->fillField(['name' => 'email'], 'test@user.com');
        $I->fillField(['name' => 'password'], 'testuserpass');
        $I->fillField(['name' => 'password_confirmation'], 'testuserpass');
        $I->click('Register', '#content form');
        $I->see('LOG OUT');
        $I->click('LOG OUT');
        $I->see('REGISTER');
        $I->click('LOG IN');
        $I->fillField(['name' => 'email'], 'test@user.com');
        $I->fillField(['name' => 'password'], 'testuserpass');
        $I->click('Login', '#content form');
        $I->see('LOG OUT');

    }
}

codeception.yml

actor: Tester
paths:
    tests: tests
    log: tests/_output
    data: tests/_data
    support: tests/_support
    envs: tests/_envs
settings:
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
extensions:
    enabled:
        - Codeception\Extension\RunFailed
        - Codeception\Extension\Recorder
  • 写回答

1条回答 默认 最新

  • dtnmnw3697 2015-11-19 09:29
    关注

    You don't really need to open firefox manually, Codeception + Selenium does it automatically when you run ./codecept run acceptance

    Also, make sure "firefox_binary" points to right path.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!