Can Codeception Use both PHPBrowser is Some tests and WebDriver in others? - codeception

New Codeception user here, so apologies in advance for what's like a super simple question. Is it possible to have a codeception project that runs some acceptance tests with the PhpBrowser driver, and others with the selenium WebDriver driver?
That is, I have an acceptance.suite.yaml that looks like this
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://localhost/'
browser: firefox
window_size: 1024x768
wait: 10
capabilities:
unexpectedAlertBehaviour: 'accept'
And a test that looks like this
#File: tests/acceptance/Science.php
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('see Science word in title ');
$I->amOnPage('/');
$I->seeInTitle('Science');
When I run
vendor/bin/codecept run
My tests run in selenium server. (yay!) However, there's other tests I'd like to run in the plain old PhpBrowser. Is this possible without creating a second codeception suite? If so, what does the configuration and/or test look like?

No, you have to use separate suites.

I think you can use WebDriver with PhantomJS browser as explained in Codeception documentation here http://codeception.com/docs/modules/WebDriver.
You need to download and run PhantomJS and then change the browser value from firefox to phantomjs in codeception configuration file.

If you need both WebDriver and PHPBrowser tests - create a separate suite.

Related

Webdriver.io: what's the difference between the capabilities and desiredCapabilities keywords?

I'm using Webdriver.io to run UI tests in a Node environment.
I'd like to run Headless Chrome and came up with the following working configuration:
{
capabilities: [{
browserName: 'chrome',
args: ['--headless', '--disable-gpu']
}
}],
services : ['selenium-standalone'],
execArgv : ['--inspect']
}
However, I can't figure out whether capabilities is deprecated or not; I'm wondering because all the examples I see reference desiredCapabilities instead.
If I use desiredCapabilities though, then Chrome runs normally, not in headless mode.
I feel like I'm missing something, but I don't know what. Is there a significant difference between the two, and is one going away?
Thanks!
If you run webdriverio through the test runner (using a wdio.conf.js file), it uses capabilities.
If you run it in standalone mode (e.g. node myTest.js), it uses desiredCapabilities

Codeception acceptance test not working with firefox

I am trying to run an acceptance test on firefox using selenium 3.0.1. I am also using wp-browser WPWebDriver module. My acceptance-suit.yml looks like this.
class_name: AcceptanceTester
modules:
enabled:
- \Helper\Acceptance
- WPWebDriver
config:
WPWebDriver:
url: 'url'
adminUsername: 'juhi.saxena#gmail.com'
adminPassword: '123456'
adminPath: '/wp-admin'
browser: firefox
webdriver.gecko.driver: 'bin/geckodriver.exe'
On runnuning this wpcept run acceptance testsCest.php I get [Facebook\WebDriver\Exception\UnknownServerException] The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded fro
m https://github.com/mozilla/geckodriver/releases
Try removing the '.exe'.
I'm running successfully with webdriver.gecko.driver: '/usr/local/bin/geckodriver'.
Also, have you placed the geckodriver.exe in the path?
I solved a similar problem with Codeception and Firefox by adding path='' to the WebDriver config section.

How to open a url/webpage in codeception acceptance testing?

Testing framework: Codeception
How to open a url/webpage in codeception acceptance testing ?
You can open an url directly by method: amOnPage
PHP-Browser
If you are using Selenium you can see here: WebDriver
You should have a webdriver enabled in your config for the suite you are using. Usually PhantomJS or Selenium for acceptance testing. You should also set a base URL. i.e.:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://localhost/'
browser: phantomjs
There are two commands:
amOnPage($page) - appends $page to URL and opens
amOnUrl($URL) - opens $URL directly
So with the above config:
$I->amOnPage("works"); //opens http://localhost/works
$I->amOnPage("http://localhost/dontwork"); //error!
$I->amOnUrl("http://localhost/works"); //opens http://localhost/works

acceptance testing with selenium and codeception, browser shows blank page

I'm using codeception with Yii2 and my configuration is as follows:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://ucms.ac.ir/admin/index-test.php/'
browser: chrome
- tests\codeception\common\_support\FixtureHelper
- Yii2
config:
Yii2:
configFile: '../config/backend/acceptance.php'
tests run, and they finish successfully, but nothing appears on the new browser tab opened by selenium. I've seen some tutorials and in those tutorials browser actually shows process of testing. also, when an error occurs and a screenshot is taken by codeception for later reference, it's only a white empty page too.
I'm on ubuntu 14.10, selenium 2.47.1 and chrome 45. it also happens when I use firefox instead of chrome.
I asked same question in codeception's github repo and here's the answer:
Don't use Yii2 and WebDriver in the same suite.
My fault, this is corrected configs:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://ucms.ac.ir/admin/index-test.php/'
browser: chrome
- tests\codeception\common\_support\FixtureHelper

Test browser code with Intern through Grunt and Phantomjs

I have been playing with Intern and made my tests work in the browser. To better integrate with my current workflow I'm trying to run my tests through grunt with phantomjs. However all my attempts have failed. I've been looking at this question as a reference Intern WebDriver and PhantomJS but can't figure out all of the steps to make it work.
First of all: Is it even possible to run the tests through grunt and phantomjs?
A little bit of info:
I don't want/can't connect to Sauce Labs or a Selenium testing environment.
I want to test browser code while having jQuery as a shimmed dependency
I have Grunt 0.4.1 and phantomjs 1.9.1 installed
I'm not testing any ajax request (as the linked question is having problem with)
I'm not familiar with neither Selenium nor Sauce Lab
If it is possible to test through grunt and phanomjs, how would I go about doing it?
I guess that I have to start the GhostDriver
phantomjs --webdriver=8910
But then what are the important pieces of info in the Intern config to make this work?
define({
proxyPort: 9000,
proxyUrl: 'http://localhost:9000/',
environments: [
{
browserName: 'phantom',
version: '1.9.0',
platform: 'Linux'
}
],
webdriver: {
host: 'localhost',
port: 8910
},
maxConcurrency: 3,
useSauceConnect: false,
// ...
});
How does the environments browserName map to phantomjs? I've tried the browserNames 'phantom' as well as 'phanomjs' with different versions and platforms (running Mac 10.7)
My Gruntfile section for intern looks like:
intern: {
phantom: {
options: {
config: 'tests/intern',
reporters: ['webdriver']
}
}
}
Running this setup without any test-suite that includes browser code outputs
'ReferenceError: document is not defined' in 'node_modules/intern/lib/reporters/webdriver.js:41:19'
Adding browser tests gives 'ReferenceError: window is not defined' in 'src/vendor/jquery/jquery-1.9.1.js:9597:5'
Running it through node gives the same 'window is not defined' error.
node node_modules/intern/client.js config=tests/intern
What am I doing wrong/missing here?
There are two problems with your Gruntfile configuration:
The default run type for the Grunt task is 'client', which means it runs the Node.js client by default, not the test runner. You need to set runType: 'runner' in your Gruntfile options to run tests against your specified environments.
The webdriver reporter is for use in a browser client only and is specified automatically by the test runner when it is needed. You should typically never use it directly. The reporter you specify in the Gruntfile should be the one you want the test runner to use; the console default is usually appropriate.
These two things in combination mean that you’ve configured Intern to try to use a reporter that only works in a browser in conjunction with the test runner inside the Node.js client, hence the error. Once corrected, the remaining configuration should work properly to run on PhantomJS, assuming it is already running on localhost at port 8910.