Giter VIP home page Giter VIP logo

Comments (8)

DavertMik avatar DavertMik commented on May 20, 2024

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.

dullus avatar dullus commented on May 20, 2024

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.

DavertMik avatar DavertMik commented on May 20, 2024

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.

dullus avatar dullus commented on May 20, 2024

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.

DavertMik avatar DavertMik commented on May 20, 2024

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.

dullus avatar dullus commented on May 20, 2024

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.

DavertMik avatar DavertMik commented on May 20, 2024

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.

dullus avatar dullus commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.