Skip to content

Instantly share code, notes, and snippets.

@JeffreyWay
Last active December 17, 2015 13:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save JeffreyWay/5615071 to your computer and use it in GitHub Desktop.
Save JeffreyWay/5615071 to your computer and use it in GitHub Desktop.
Codeception Laravel4 module issue. Line 7 makes this fail for me. It only responds to the label's body. Not name or id of the input. 20 second video example: http://d.pr/v/hn0q
<?php
$I = new TestGuy($scenario);
$I->wantTo('register for a new account');
$I->amOnPage('/register');
$I->see('Register', 'h1');
$I->fillField('email', 'joe@sample.com');
$I->fillField('Password:', 'password');
$I->click('Register');
$I->seeCurrentUrlEquals('/login');
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>Register</title>
</head>
<body>
<h1>Register</h1>
{{ Form::open() }}
{{ Form::label('email', 'Email:') }}
{{ Form::text('email') }}
{{ Form::label('password', 'Password:') }}
{{ Form::text('password') }}
{{ Form::submit('Register') }}
{{ Form::close() }}
</body>
</html>
@DavertMik
Copy link

It's ok. To match element by ID you should use CSS selector, or XPath locator.
Basically, smth like this:

<?php

<?php
$I = new TestGuy($scenario);
$I->wantTo('perform actions and see result');
$I->amOnPage('/posts');
$I->see('All Posts');
$I->click('Add new post');
$I->fillField('#title', 'Hello world again');
$I->fillField('#body', 'And greetings for all');
$I->click('Submit');
$I->see('All Posts');
$I->see('Hello world');

At first element is searched by label/text/etc (depending on element). There are pretty complex XPath locators in Mink and BrowserKit to guess the proper element. But if they fail Codeception retries with matching by CSS. If CSS matching fails, Codeception tries to use it as XPath.

Bruteforce that works:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment