I'm using Behat\Mink\Driver\Selenium2Driver. This is the #Then function for one of my features:
/**
* #Then /^I should see "([^"]*)"$/
*/
public function iShouldSee($result)
{
$verification = new WebAssert($this->session);
try
{
$verification->pageTextContains($result);
}
catch(ResponseTextException $e)
{
printf("something went wrong");
}
}
If I write a scenario where the assertion should pass, I have no problem: it runs properly and creates the output file in junit format that I will pass to Jenkins later.
But if I change the scenario so it should fail, the execution is interrupted after the failed assertion text and I get this message:
Then I should see "my text" # MyCompany\MyBDDBundle\Features\Context\FeatureContext::iShouldSee()
The text "my text" was not found anywhere in the text of the current page.
PHP Fatal error: Call to a member function text() on a non-object in C:\BitNami\wampstack-5.4.15-0\frameworks\symfony\vendor\behat\mink-selenium2-driver\src\Behat\Mink\Driver\Selenium2Driver.php on line 464
Fatal error: Call to a member function text() on a non-object in C:\BitNami\wampstack-5.4.15-0\frameworks\symfony\vendor\behat\mink-selenium2-driver\src\Behat\Mink\Driver\Selenium2Driver.php on line 464
I've been looking the Selenium2Driver.php file and line 464 is inside function getText($xpath) that I just don't use.
And finally, having the test been interrupted, the junit file that is created as an output only contains the XML header, although there were many passed scenarios.
<?xml version="1.0" encoding="UTF-8"?>
Why is the test working when the assertion passes but it crashes when it fails?
Related
I'm performing dusk test with lighthouse inside it like:
class ExampleTest extends DuskTestCase
{
use DatabaseMigrations;
public function testExample()
{
//this is a mutation for adding more stuff
$this->graphQL('mutation ...')
$this->browse(function (Browser $browser) use ($url) {
$browser->visit($url)
//asserts...
});
}
}
And on my mutations, the error message is:
"""Lighthouse failed while trying to load a type: typeFromMySchemaExample \n
\n
Make sure the type is present in your schema definition.\n
"""
I've already seen that schema is valid by:
php artisan lighthouse:validate-schema
And check the schema by it self to see if that type is present with:
php artisan lighthouse:print-schema
And cleared all configs/cache from laravel and lighthouse as in solution#1 with no success.
In my composer, I have:
laravel/dusk in v6.12.0
nuwave/lighthouse in v5.2.0
phpunit/phpunit in v9.5.2
ps:I commented that type in the graphql and the error keeps going by my import order in the schema.graphql.
I'm using selenium-server version 3.0.1 and nightwatch version ^0.9.12 on node 8.9.0. My e2e test do run, clicks work, and reading the DOM works, but setValue just doesn't.
For example, the following test:
browser
.url("...")
.waitForElementPresent('select[name=foo]', 5000)
.click('select[name=foo] option:nth-child(2)')
.waitForElementPresent('input[name=bar]', 5000)
.setValue('input[name=bar]', "hello world")
.getValue('input[name=bar]', function(input) {
this.assert.equal(input.value, "hello world");
})
.end();
will open the url, wait for foo and click the second option. It will wait for bar, then fails:
Running: test
✔ Element <select[name=foo]> was present after 24 milliseconds.
✔ Element <input[name=bar]> was present after 28 milliseconds.
✖ Failed [equal]: ('' == 'hello world') - expected "hello world" but got: ""
at Object.<anonymous> (/test/e2e/specs/test.js:49:21)
FAILED: 1 assertions failed and 2 passed (4.692s)
_________________________________________________
TEST FAILURE: 1 assertions failed, 2 passed. (4.9s)
✖ test
- run through apply process (4.692s)
Failed [equal]: ('' == 'hello world') - expected "hello world" but got: ""
If I replace the setValue with a delay and enter a value by hand, the test will pass, so getValue is working.
This does run, and pass, on other systems, but I can't get it working on my own so I think it's a selenium-server issue.
I've tried a lot of the 101 fixes, clearing the npm cache, re-running an npm install, etc. But with no errors other than the failure, how do I debug this?
Assuming you are trying to test using Chrome, you need to update your ChromeDriver.
Chrome 65 was released recently and older ChromeDriver versions are apparently incompatible with it.
Download the latest one from the downloads page.
Make Nightwatch use it, nightwatch.json -
{
...
"selenium": {
...
"cli_args": {
"webdriver.chrome.driver": "path/to/chromedriver.exe"
Assuming Nightwatch uses it (you can see which one it uses using the Windows Task Manager - assuming you are using Windows - look for the command line of chromedriver.exe), setValue should now work again.
The error says it all :
Failed [equal]: ('' == 'hello world') - expected "hello world" but got: ""
In your code block you have induced wait for the WebElement identified as 'input[name=bar]' and next invoked setValue() which is successful as follows :
.waitForElementPresent('input[name=bar]', 5000)
.setValue('input[name=bar]', "hello world")
Now the JavaScript associated with this WebElement identified as 'input[name=bar]' will require some time to render the value within the HTML DOM. But in you code block you are trying to access the entered value (in the previous step) too early. Hence your script finds <null> as the value.
Solution
You need to induce a waiter i.e. expect clause for the value to be rendered within the HTML DOM through the associated JavaScript as follows :
.waitForElementPresent('input[name=bar]', 5000)
.setValue('input[name=bar]', "hello world")
.expect.element('input[name=bar]').to.have.value.that.equals('hello world');
.getValue('input[name=bar]', function(input) {
this.assert.equal(input.value, "hello world");
})
While attempting to fix another issue I'm having (Behat tests not running on CircleCI) I noticed that any argument I provide to bin/behat is not accepted. For example, if I run bin/behat -h, I don't get the help options. It just runs my tests. If I rename my behat.yml file to behat-test.yml, and try to run bin/behat --config behat-test.yml, I get an error stating that the FeatureContext can't be found. No matter what I type after bin/behat it is ignored and it runs my tests.
I added a var_dump in Behat's Application.php file and it is not capturing the arguments and prints an empty array. e.g.
public function run(InputInterface $input = null, OutputInterface $output = null)
{
if (null === $input) {
$input = new ArgvInput();
}
var_dump($input);
Turns out, due to the nature of the CMS I'm working with I had to fudge some $_SERVER variables, and I had hard-coded $_SERVER['argv'] = array(), and forgot about it, which explains why no arguments were working.
Can we just catch the adapter calling failure error details? sample code :
var invocationData = {
adapter : 'UploadAdapter',
procedure : 'uploadImage',
parameters : [uuid, base64Str]
};
WL.Client.invokeProcedure(invocationData, {
onSuccess : uploadImageSuccess,
onFailure : uploadImageFail,
timeout : 60000,
});
I've already tried this:
function uploadImageFail(result){
WL.Logger.debug(JSON.stringify(result);
}
But it was just:
{"invocationContext":null}
My scenario : I'm working on an image uploading adapter (via cordova), and sometimes the uploading may fail. I can easily catch the error message returned from the backend service (which is handled in the uploadImageSuccess function), but it's not easy to retrieve the error logs when the invoking procedure goes wrong.
I am not sure you need to JSON.stringify it the result object. Instead you may want to simply use result.errorMsg.
I also googled, and it produced results on the code that needs to be used... so I would try the options provided in the following articles:
https://www.ibm.com/developerworks/community/blogs/worklight/entry/handling_backend_responses_in_adapters?lang=en
http://www.ibm.com/developerworks/websphere/techjournal/1212_paris/1212_paris.html
I am using behat with a zombie driver to test my application. Now I am trying to click on an element (a td), to fire an ajax request. But when clicking this element I receive the error:
Error while processing event 'click' (Behat\Mink\Exception\DriverException
The code I use is from this thread
Nowhere on the internet I can find someone with the same error message, so I have no clue how to solve this.
The HTML I want to click on looks like this:
<td value="2" onclick="switchStatus(this.id); updateScores();; return false;" id="37_12_2">2</td>
These javascript functions do an ajax call to the server and do nothing with the saved result (no success method).
The test function I use looks like this:
/**
* #Given /^I click td "([^"]*)"$/
*/
public function iClickTd($id)
{
$locator = "#$id";
$element = $this->getSession()->getPage()->find('css', $locator);
if (null === $element) {
throw new \InvalidArgumentException(sprintf('Could not evaluate CSS selector: "%s"', $locator));
}
$element->click();
$this->getSession()->wait(1000);
}
And in the test I have:
And I click td "37_12_2"
The behat.yml:
default:
suites:
default:
contexts:
- FeatureContext:
- http://localhost/
extensions:
Behat\MinkExtension\ServiceContainer\MinkExtension:
base_url: http://localhost/
sessions:
default:
goutte: ~
javascript:
zombie:
node_modules_path: '/usr/lib/node_modules/'
Used versions:
"phpunit/phpunit": "4.5.*",
"phpspec/phpspec": "~2.1",
"behat/behat": "~3.0",
"behat/mink": "~1.6",
"behat/mink-extension": "~2.0",
"behat/mink-goutte-driver": "*",
"behat/mink-zombie-driver": "~1.2"
npm v1.4.28
php 5.6
Does anyone know what goes wrong, and how I can make this function work?
The actual problem was a wrong ajax request. Using a real webbroser the ajax call went right, but using zombieJS this call went to a wrong url.
When someone else has the same exception, you can view your real problem by changing the following part in the ZombieDriver.php:
From:
$out = $this->server->evalJS($js);
if (!empty($out)) {
throw new DriverException(sprintf("Error while processing event '%s'", $event));
}
To:
$out = $this->server->evalJS($js);
if (!empty($out)) {
echo $out;
throw new DriverException(sprintf("Error while processing event '%s'", $event));
}
$out contains the actual error message of an ajax call.