Skip to content
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

$I->seeElement required html tag? #5556

Closed
cosinus90 opened this issue Jun 19, 2019 · 7 comments
Closed

$I->seeElement required html tag? #5556

cosinus90 opened this issue Jun 19, 2019 · 7 comments

Comments

@cosinus90
Copy link

I have AJAX endpoint that returns html markup of the items loaded on the page scroll. This isn't a jquery and isn't a full HTML document which I mean starts from HTML tag. My endpoint returns items that later will be included in the document like

$('#id').append(html);

I guess it's a common situation. But when I try to test this result for an element - it fails:

$I->sendAjaxRequest('POST', '/channel/search?sort_column=false&sort_dir=false', [...]);
$I->seeElement('.offset');

First line of AJAX response is

 <tr class="offset" data-offset="10" ></tr>

Looks like the seeElement function (and others) require the HTML document starting from HTML tag? Is there any possibility to test the response in my case?

@Naktibalda
Copy link
Member

You could use seeInSource to match a bit of HTML.

$I->seeInSource('<tr class="offset"');

@ThomasLandauer
Copy link
Member

So what are the exact requirements for seeElement() to work? And does the same apply to $I->see('...', [XXX]) as well?

ThomasLandauer added a commit to ThomasLandauer/Codeception that referenced this issue Oct 21, 2020
Mentioning `<html>` tag requirement. See Codeception#5556
Question: Is `<html>` enough?
@Naktibalda
Copy link
Member

How does it fail?

@ThomasLandauer
Copy link
Member

$I->sendAjaxPostRequest(...);
$I->seeElement(['css' => 'form']);

fails with:

Step See element {"css":"form"}
Fail Element located either by name, CSS or XPath element with '"css":"form"' was not found.

@ThomasLandauer
Copy link
Member

Just did some testing with see():

  • When I just pass the string (see('foo');), it works.
  • When I also pass a CSS selector (see('foo', ['css' => '.class']);), it does never work - no matter if the Ajax response has an <html><body> skeleton or not.

@Naktibalda
Copy link
Member

I looked into this, and I think that it is a bug that any assertion sees response of Ajax request.

As far as I remember, the intention was that Ajax methods make requests that cause some side effects in backend, e.g. update database record, but the browser stays on the same page where it was before making Ajax request and the test can click or submitForm on that page.

@DavertMik Can you confirm that?

@DavertMik
Copy link
Member

sendAjaxRequest was one of the first methods introduced to Codeception to test my project I worked on in 2012. The fun fact it didn't change much since that time.

Originally, it was dealing with HTML responses because our site used to display popups via HTML.

I may assume that nowadays underlying parser doesn't understand HTML without <html> tag, so this problem can be very hard to solve. Should we wrap response in <html> ?

Anyway, there are less and less applications using Ajax approach, so I think this is minor issue.
But if someone comes with Pull Request to InnerBrowser which wraps HTML responses with HTML tag, I am ok to accept it.
(or any other solution to this issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants