1

I have multiple similar websites that I want to test. Here's the current approach:

  1. Clone an existing codeception project
  2. Adjust the variables
  3. Add some additional specific test cases if required

This works just fine, but has one issue. If the general test case changes that means that I have to go into every project and make the changes. So what I would rather see is a way to include a generic top level test case in every project and call it with a parameter.

I tried so with a simple include() statement, but unfortunately this doesn work. And ideas how I can accomplish this?

Here some code of my initial try:

/home/tests/site1/tests/acceptance/isOnlineCept.php

include("../1generic_tests/isonline.php");
$I = new AcceptanceTester($scenario);
$I->am('user');
$I->wantTo('see the content of the site');
$I->lookForwardTo('see the homepage');
$I->amOnPage('/');
$I->see("Tech, Geek and Rock'n'Roll");

The file I include looks like this

$I = new AcceptanceTester($scenario);
$I->am('user');
$I->wantTo('see the content of the site');
$I->lookForwardTo('see the homepage');
$I->amOnPage('/');
$I->see('something else');

Unfortunately it fails with this error

[PHPUnit_Framework_Exception] Undefined index: class

Maybe include is not the right way to do it, but what would be a better way?

4
  • Please provide the code that did not work as we have nothing to go on with how your question is currently stated. Commented Dec 8, 2016 at 16:44
  • Added some code Commented Dec 8, 2016 at 20:29
  • Why don't you use page objects and declare the function in page objects. Call it with parameters. Commented Jan 4, 2017 at 12:31
  • do you have some sample code? Commented Jan 6, 2017 at 7:58

1 Answer 1

1

You can use Page Object for this.

Create one Constants.php file using Page Object where you can define all the selectors.

Create one other file where you can keep all common operation going to be performed. E.g. Settings.php file where you can have all methods as per your requirement. you can define it with parameter too.

To access any selector and/or method from declared under page dir can be accessible by using the following line.

use Page\Constants as ConstantsPage;

To access any selector from any specific file

FileNamePage::$selectorName;

To access any method, first create the object and then call the method. E.g.

$settings = new SettingsPage( $I )

$settings->methodName();

To call the method and/pr selector in the same file.

self::selectorName;

self::methodName();

Hope this will be helpful.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.