-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error by using selenium #1
Comments
You can't use XPath as a selector, Thus, click("/html/body/ul/li[2]/a") won't work. Also, from my perspective, it's good to avoid that complex paths. As designs and markups may change, and that shouldn't break tests. Don't use comments in your scenario. Better use methods amGoingTo and expect, for commenting. Writing your comments with them makes scenarios more readable. |
Using complex paths is intentional, our acceptance tests should fail if somebody changes CSS or UI elements. Comments were added only to this issue ticket as explanation. Thanks anyway, any plans to support XPath in future versions ? I have also one question when running test with phpbrowser:
how can I access ajax result within test ? |
I will think on adding XPath. As for me it looks much harder to read XPath then CSS selectors and names. As for ajax request... If your request returns HTML, your see commands will be executed for that response. |
I mean, in debug mode I see json response, can I get that string somewhere from $I object ?
|
I assume you want to check your JSON response? The $I can't return anything, it's a basic limilitation. All actions and assertions can be performed as a part of $I instance. I recommend you to write helpers for your custom assertions. Check out class 'tests/_helpers/WebHelper' and Modules section of documentation. From your helper you can access current Mink session instance and perform any actions on it. |
I don't want that custom function in WebHelper makes assertion. I want that it returns variable that can be used in next fillField test. For example:
And here is another problem, I had no luck to connect to that mink session from WebHelper::getAjaxResponse. I need something like in module/PhpBrowser.php function call() :
so I can parse it in WebHelper::getAjaxResponse and return value (or if it is not possible that $I methods return value, then I will do at least assertion in helper). Can you write me example how to access current mink session from WebHelper class ? |
Sure. That principle is covered in Modules part of Guides. In helper: <?php
$session = $this->getModule('Selenium')->session;
?> Every module has it's public API. You can execute all public methods and properties from other modules and helpers. |
Thank you, works now as I want :-) Now I can do all needed ajax asserts in webhelper. $session = $this->getModule('PhpBrowser')->session;
$result = $session->getStatusCode();
$result2 = $session->getResponseHeaders();
$result3 = $session->getCurrentUrl();
$result4 = json_decode($session->getPage()->getContent(), true); |
When I test acceptance test with Selenium I got some bug. Maybe it is related to Xpath element positionoing ? All other test with selenium runs just fine, just this one throws error.
searchAjaxCept.php:
D:\codecept run acceptance --debug
I cannot use CSS selector unless some changes are made in web page source, so then I get:
The text was updated successfully, but these errors were encountered: