🇮🇳India @monalipatil

Account created on 10 October 2012, about 12 years ago
#

Recent comments

🇮🇳India monalipatil

Thanks for sharing you cypress testing strategy.

So Cypress has nothing to do with Drupal code. I think whatever features testing you have mentioned above should get covered by test automation using jmeter. But I still think that the each and every line of code developer has written should get tested somehow.

I tried PHPUnit but it requires entire Drupal core to be installed in a same or different database and this should be the part of Unit test code itself. But Drupal core installation itself takes 10-20 mins like it takes when we install fresh Drupal from browser.

Any alternate way where can skip Drupal core installation and execute our custom unit test within few seconds? Please let me know if you have done this before. It would be more helpful.

Thanks,

🇮🇳India monalipatil

Thank you @Jaypan for the quick response on this.

I have tried 'npx cypress run' and it has executed all the the .cy.js file within cypress folder including example tests.

I  have few other questions. As you said in this thread we can use cypress for end to end testing and unit test for executing custom classes (controllers, module files etc).

My major focus is executing below things using Cypress-

-Custom classes (controllers + module files hooks)

-Accessing all the URLs including, login, logout,

-Create/update/delete node for different content types and taxonomies,

-Different views URL's, add/edit/delete users,

-Performing some AJAX calls that are custom routing,

-Loading  multiple dependent dropdown (this is custom)

- Custom form validations and submissions

- Few third party API calls from custom code that are used to translate the content

- Creating XML files for different content (export/import through custom code)

- and few more URLs that are custom things only.

Is it possible to test above things only with cypress?

Note - I have tried PHP unit test but it takes lot of time just to prepare Drupal core before executing the basic test cases to check 200 status code of the given URL with the custom path like - modules/custom/module_name/tests/src/Functional/FirstFunctionalTest.php

Please share your thoughts and suggestions. I am confused between php unit test and cypress. Cypress looks good but not sure whether it will cover my entire custom modules/features code. My end goal is to verify that the code I have written is not having any error when I push the code from local to repo and also the features I developed using views/blocks are accessible to end users.

Thank you and sorry for the too many questions here.

🇮🇳India monalipatil

Thank you Jaypan and ressa for your help and sorry for the late response here. :)

I have successfully installed cypress at the latest Drupal 10 root directory on local (Windows 10 with Xampp running on it).

After running the comment 'npx cypress open' in GitBash it opens cypress window and from there it opens separate chrome window with the default tests. I have added a sample tests called 'Loads the front page' and 'Tests logging in using an incorrect password'.

Now the next question is how to run it like phpunit test cases we usually runs. I have checked the instructions given here by you.

https://www.drupal.org/docs/develop/automated-testing/browser-testing-us... →

As you mentioned, "Just enter the "test" folder, and run this command to run a single test:", which "test" folder you are referring here?

My test cypress file is located at \cypress\integration\test.cy.js (I have created a separate folder integration as I read in some other documentation).

And how the commands will execute when needed? for example, I have modified some module/controller files in Drupal and now I want to push the code. but before pushing the code I want to execute my cypress tests which are located at \cypress\integration\test.cy.js . I know that running 'npx cypress open' will open the cypress screen and from there I need to select the browser and click on start E2E testing. This will be manual process always whenever I want to execute the tests?

Please confirm.

Thanks in advance.

🇮🇳India monalipatil

What is the twig file name you have rendered these variables?

I have created a content type with title, body and images (multiple) fields. I have views-view-unformatted--machinename--page-1.html.twig file to render the views output (multiple rows). It has below code.

{% for post in rows %}

{{ post.content['#row']._entity.title[0].value }}

{{ post.content['#row']._entity.body.value }}

{% endfor %}

I'm able to render the title and body field. I have one image field attached to node which accepts multiple images. How can I print that in the same twig file I have above? Do I need additional field twig template?

Thanks,

🇮🇳India monalipatil

Any good tutorial or documentation to start the unit test cases for views pages and controllers? It would be helpful if you can also point to the resources for Cypress with Drupal.

Thanks,

🇮🇳India monalipatil

When you says 'unit testing on classes', What if I have one form_alter and view pre render hook in module file? Does this code also requires unit test? which class or object they refer?

Production build 0.71.5 2024