Phantomjs Behat form field not found when executing in my server - phantomjs

everyone, could I have some help please ?
I try to run a test with Behat/Mink and Phantomjs. It works locally without Phantomjs, but not on my server.
When I launch my tests, I've got this problem :
#javascript
Scenario: Searching for a page that does NOT exist
Given I am on "http://fr.wikipedia.org/wiki/Wikip%C3%A9dia:Accueil_principal"
When I fill in "searchInput" with "Glory Driven Development"
Form field with id|name|label|value "searchInput" not found.
My settings in behat.yml is as following
phantomjs:
context:
class: 'FeatureContext'
extensions:
Behat\MinkExtension\Extension:
goutte: ~
selenium2:
wd_host: "http://localhost:8643/wd/hub"
capabilities:
proxy:
proxyType: direct
My test is as following
#javascript
Scenario: Searching for a page that does NOT exist
Given I am on "http://fr.wikipedia.org/wiki/WikipC3%A9dia:Accueil_principal"
When I fill in "searchInput" with "Glory Driven Development"
And I press "searchButton"
Then I should see "Search results"
I can't understand why it says : "Form field with id|name|label|value "searchInput" not found". I have launched phantomjs and even selenium.
Does someone has an idea ? Thank you

I was trying same scenario today.
Driver is complaining about not finding the element. So I debug a bit the test case and found that the page browsed by driver was different than the one expected.
When the driver does: $this->getSession()->getPage(). Be sure you are in the expected page and receiving expected html.

Related

Running Chrome from PortableApps with Selenium WebDriver fails

I've got C# Selenium project and want to run portable Chrome downloaded from here.
My chromeOptions are:
chromeOptions.BinaryLocation = Path.GetFullPath("C:\", "tests.browsers", "windows", "chrome", "GoogleChromePortable.exe"));
chromeOptions.AddArgument("--enable-logging");
chromeOptions.AddArgument("--v=1");
chromeOptions.AddExtension(Path.Combine("path", "to", "kontur-plugin.crx"));
But when I run the test, Chrome opens and shows this:
(notifications say "Failed to login %EXTENSIONNAME%, click to load it once again)
chrome_debug.log contains no errors.
What am I doing wrong? How can I figure out what is the problem with?
this might help you - Stackoverflow post
also, your CRX file should add as a file, not just the path.

Codeception: Check if element has focus?

Is there a way to assert that an element (e.g. input or link) has the keyboard focus? I'm using Codeception with Selenium. Couldn't find anything on http://codeception.com/docs/modules/WebDriver
A reliable source told me this works:
$I->executeJS('return $("#element").is(":focus")');
Happy testing!
Some more details to the answer by #sunomad
Activate Codeception's Asserts Module in your acceptance.suite.yml:
modules:
enabled:
# ...
- Asserts
Then use this in an Acceptance test:
$focus = $I->executeJS('return $("#element").is(":focus")');
$I->assertEquals(true, $focus);
Works (through Selenium) with Firefox and Chrome. However, it does not work with PhantomJS - see this issue: https://github.com/ariya/phantomjs/issues/10427
To complete the #sunomad's answer.
If you use the code line :
$I->executeJS('return $("#element").is(":focus")');
You got this error :
[Facebook\WebDriver\Exception\UnknownServerException] unknown error: $ is not a function
Switch $ by jQuery
$I->executeJS('return jQuery("#element").is(":focus")');
And it works !

Meaning of "browser" in Selenium's requested capabilities

I am developing functional tests with Behat, Mink and Selenium. I have long been perplexed by the "browser" item included in the Capabilities object that's created with each new session:
02:13:48.592 INFO - Got a request to create a new session: Capabilities
[{browser=safari, name=Behat feature suite, browserName=safari, [...] }]
As far as I can tell, only "browserName" has any effect - if I set "browserName" to "safari" and "browser" to any other value, then the new session will be created on a node that can run Safari.
So why does Mink include the value? It must surely have some purpose, but I haven't found any documentation explaining it.
A possible answer would be:
browser and browserName is the same capability for the browser to use.
If you are using capabilities parametter to set up the desired capabilities to use, then the browserName has priority.
If you are NOT using capabilities parametter you can also setup the browser name by using browser.
To get a better picture please take a look to getConfig method at arrayNode('selenium2') line from Extension.php located in vendor > behat > mink-extension > src.
Hope this will help you in getting an answer or at least point you to the right direction.

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

Ghostdriver with PHPUnit

I'm attempting to use PhantomJS as a browser for PHPUnit Selenium tests.
I've set Selenium running in grid mode, and started phantomjs with webdriver, and registered it to the grid, as in the GhostDriver Readme.
When I run a selenium test, it fails with an unknown command error - GhostDriver just doesn't understand what PHPUnit is saying.
[ERROR - 2013-05-12T16:23:06.326Z] RouterReqHand - _handle - Thrown => {
"message": "Request => {\"headers\":{\"Accept\":\"*/*\",\"Connection\":\"Keep-Alive\",\"Content-Length\":\"85\",\"Content-Type\":\"application/x-www-form-urlencoded; charset=utf-8\",\"Host\":\"127.0.0.1:4444\"},\"httpVersion\":\"1.1\",\"method\":\"POST\",\"post\":\"cmd=getNewBrowserSession&1=phantomjs&2=https%3A%2F%2Ftest.testurl.com%2F&\",\"url\":\"/\",\"urlParsed\":{\"anchor\":\"\",\"query\":\"\",\"file\":\"\",\"directory\":\"/\",\"path\":\"/\",\"relative\":\"/\",\"port\":\"\",\"host\":\"\",\"password\":\"\",\"user\":\"\",\"userInfo\":\"\",\"authority\":\"\",\"protocol\":\"\",\"source\":\"/\",\"queryKey\":{},\"chunks\":[\"\"]}}",
"name": "Unknown Command",
"line": 87,
"sourceId": 139810136032448,
"sourceURL": ":/ghostdriver/request_handlers/router_request_handler.js",
"stack": "Unknown Command: Request => {\"headers\":{\"Accept\":\"*/*\",\"Connection\":\"Keep-Alive\",\"Content-Length\":\"85\",\"Content-Type\":\"application/x-www-form-urlencoded; charset=utf-8\",\"Host\":\"127.0.0.1:4444\"},\"httpVersion\":\"1.1\",\"method\":\"POST\",\"post\":\"cmd=getNewBrowserSession&1=phantomjs&2=https%3A%2F%2FFtest.testurl.com%2F&\",\"url\":\"/\",\"urlParsed\":{\"anchor\":\"\",\"query\":\"\",\"file\":\"\",\"directory\":\"/\",\"path\":\"/\",\"relative\":\"/\",\"port\":\"\",\"host\":\"\",\"password\":\"\",\"user\":\"\",\"userInfo\":\"\",\"authority\":\"\",\"protocol\":\"\",\"source\":\"/\",\"queryKey\":{},\"chunks\":[\"\"]}}\n at :/ghostdriver/request_handlers/router_request_handler.js:87",
"stackArray": [
{
"sourceURL": ":/ghostdriver/request_handlers/router_request_handler.js",
"line": 87
}
]
}
This same question was asked and closed unanswered on the GhostDriver site with the suggestion that it's PHPUnit to blame. That may be the case, but I'm still no nearer to making this work. Does anyone have any idea how to fix it?
It looks like you are using a test class extending PHPUnit_Extensions_SeleniumTestCase. Use PHPUnit_Extensions_Selenium2TestCase instead.
Unfortunately, that's not the end of the story. The syntax of the Selenium-related methods changes when you swap out the base class.
The dated PHPUnit_Extensions_SeleniumTestCase class
uses the Selenium RC API
does not support Phantom.js as a browser
requires the "traditional" syntax as documented here
works fine with code which is generated in Selenium IDE and exported with the help of the "Selenium IDE: PHP Formatters" plugin.
By contrast, PHPUnit_Extensions_Selenium2TestCase
uses the WebDriver API
supports Phantom.js
requires a different set of commands which is not well documented - this test case demonstrates it by example, and that's about it
does not work with code exported from Selenium IDE without an extensive rewrite.
So it is possible to run PHPUnit-driven Selenium tests faster with PhantomJS, but it does come at a cost.