You might want to use macOS'ses built in wifi diagnostics
Wi-Fi Recommendations. Click Wi-Fi in Control Center or the menu bar and check for a menu item named Wi-Fi Recommendations. If you see it, your Mac has detected an issue and has recommendations. Choose Wi-Fi Recommendations to learn more.*
Wireless Diagnostics. Press and hold the Option key on your keyboard while clicking Wi-Fi in Control Center or the menu bar, then choose Open Wireless Diagnostics from the menu. Learn more about using Wireless Diagnostics to analyze your wireless environment.
See this link for further reference
If your Mac isn't connecting to the internet over Wi-Fi - Apple Support