wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
340 stars 130 forks source link

Local tests setup #271

Closed navjot50 closed 2 years ago

navjot50 commented 3 years ago

Automated the setup of local Wordpress instance to get a totally ready container to run integration tests against.

A python script makes use of selenium to interact with the Wordpress instance and completes the installation of Wordpress, sets up the Wordpress user, sets up Wordpress settings, configures and activates all the required plugins.

At the moment the enable-application-passwords plugin is added in the dev folder in tar.gz compression, however this can be totally removed from source of this repo if you approve the PR https://github.com/wp-net/wordpress-docker-compose/pull/1 , then the plugin can be directly taken from the web.

Finally, containers-startup scripts are added with sh and ps1 extension, which are the startup scripts for all the required containers.

ThomasPe commented 3 years ago

wow, a lot to unpack - thank you so much for the effort. I haven't worked with selenium myself yet (I understand what it does) - is there any advantage doing the setup like this instead of using wpcli like we do here? https://github.com/wp-net/wordpress-docker-compose

navjot50 commented 3 years ago

You are welcome. Personally, I never knew about wp-cli, which led me to think of selenium to do some UI interactions to setup the wordpress instance. Selenium had a nice support for docker as well. Also, if in future more plugins would be required to setup the instance, then we will require changes in the python script only (I prefer code changes as a dev). However, I will have a look at the wp-cli way that your link suggests. If you think the wp-cli way is easier, then I may contribute via a new branch with wp-cli automation.

ThomasPe commented 3 years ago

I don't know about easier, that's why I haven't set it up yet for local debugging. :D I see your script basically just does the manual steps described in install.md, let me run it to see how it works for me 👍

ThomasPe commented 3 years ago

I'm still running into a few issues on windows, mainly because using port 80 is blocked by (I assume) IIS. When changing the port to 8080 the http://wordpress doesn't seem to work anymore, and with localhost:8080 or 127.0.0.1:8080 the selenium container does not have access to WordPress it seems.

navjot50 commented 3 years ago

Ok. Yes, if you change the port to 8080 then we will need to change the uri in the selenium script. I went ahead with 80 because in the WordPressPCL.Tests.Selfhosted.Utility.ApiCredentials we have the property public static string WordPressUri = "http://localhost/wp-json/"; which is exposing wordpress on port number 80. I can change everything to work for 8080 but this will require to change WordpressUri to http://localhost:8080/wp-json/. Should I make changes for 8080?

ThomasPe commented 3 years ago

That would be great, thanks

ThomasPe commented 2 years ago

sorry for the late reply, still trying to run this script on Windows (in this case 11), but I'm stuck. Will try on my other W10 machine. image

navjot50 commented 2 years ago

This time the python bot started, but failed in between. This might happen due to chrome crash inside the container. I tested it on a Mac and Windows 10 with fairly good hardware specs, and it was working fine. I would suggest to give it one more try because I just tested it again now and it worked. If it doesn't work this time then I will think of wp-cli solution.

Edit: I just tested it on Windows 10 Pro build 19043 and all worked fine. I guess that the shm_size argument may not yet be properly working on Windows 11 as it is one of the arguments that is mentioned in selenium's docker image that it prevents chrome crashes inside the container.

ThomasPe commented 2 years ago

I was able to run it on my Surface Book 2 now, the issue was that the auto-update of Docker Desktop was stuck. After manually updating to the latest version it ran without a hitch. Only problem I'm still facing is that I can neither access wordpress in the browser nor can I run the tests against it. Any ideas what the issue might be? Otherwise I think we can merge.

navjot50 commented 2 years ago

Yes, the wordpress is not accessible via browser on the local (for that a reverse proxy like nginx will be needed). However, that is not needed because the purpose of this container is to only run tests against (throwaway containers). I was able to run the test suite both in Jetbrains Rider and VS2019 once I have the containers script fully executed. What error did it give you while running the self hosted test suite?

ThomasPe commented 2 years ago

my bad, I ran it with the wrong runsettings. A few tests are still failing, but those don't seem to be any general problems with your PR.

navjot50 commented 2 years ago

Yes, I have a separate PR for their fix.