Comments (8)
You can't use XPath as a selector, Thus, click("/html/body/ul/li[2]/a") won't work.
Better use link names in 'click' action.
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.
from codeception.
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:
$I->sendAjaxGetRequest("/url/", array('term' => "mus"));
how can I access ajax result within test ?
from codeception.
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.
from codeception.
I mean, in debug mode I see json response, can I get that string somewhere from $I object ?
Suite acceptance started
Trying to test ehmk/searchajax (searchAjaxCept.php)
Scenario:
* I am on page "/"
* I send ajax get request ["/url/",{"term":"mus"}]
=> Request (GET): /url/?term=mus {"term":"mus"}
=> Response code: 200
=> {"results":[{"name":"lmusic","url":"/lst?cat=1050","desc":""},
{"name":"museums","url":"/lst?cat=1031","desc":""}],"code":200,"status":"OK"}
from codeception.
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.
from codeception.
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:
$I->sendAjaxGetRequest("/url/", array('term' => "mus"));
$name = $I->getAjaxResponse("name");
//getAjaxResponse is defined in WebHelper, does its magic with mink session,
//retrieves "name" from response JSON and will return it
$I->fillField("input#search_input", $name);
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() :
$this->session->getStatusCode()
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 ?
from codeception.
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.
from codeception.
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);
from codeception.
Related Issues (20)
- Out of memory issue with PHPUnit 10.4.1 HOT 4
- Code coverage stopped working after upgrading 4 to 5 HOT 5
- update actions ver
- Output messages don't make sense HOT 4
- Try-catch in the second test catches fail in the first test HOT 6
- Call to srand() with non-int fails with PHP < 8.3
- unit test case error on container HOT 2
- No way to run invividual tests in groups
- Providing null data with Examples annotation fails HOT 3
- skip_cleanup_if_failed documentation HOT 1
- Support phpunit 11 HOT 1
- "No primary site exists" only when running unit tests - Craft 4 Pro. No issues with functional and acceptance tests in same environment HOT 4
- Using Symfony 7 Clock ClockSensitiveTrait causes a LogicException HOT 2
- Future of Codeception? HOT 4
- Can I change the format of the exception display? HOT 2
- coverage: whitelist: exclude option has no effect since PHPUnit 11.0 HOT 10
- Running with --no-ansi still uses color HOT 1
- Codeception 5 + Symfony 6 HOT 2
- Run build command without bootstrap
- [JsonException] Non-backed enums have no default serialization
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codeception.