How to disable network at browser level not virtual machine level

my scripts run on vm1 and execute on client machine(vm2). I have to test- if I disable the client machine’s network and connect in default timeframe, it should get interactive.
Now, my question is: can I get disconnect the network at browser level, so that my scripts run continuously at machine level using robot/selenium/python??

Probably not possible other than something else that approximates a “disconnect of VM2”, at browser level.

There is no way to configure network connectivity at browser level other than via HTTP/SOCKS proxies. So you could configure a connection to a non-existent proxy, and that would cause the browser to fail connecting to any site. Then undo/disable the fake proxy configuration and browser should be able to reconnect. You either configure that at the browser config via Selenium, or you can use BrowserMobProxy as part of your test to manage the proxy portion. Configuring the proxy at the system level (Mac or Windows for example) will disrupt your network connection between VM1 and VM2, so you don’t want to do that.

An alternative option could be to handle network management (enable/disable of actual network on VM2) via local code/executable that you run from VM1 asynchronously, since you expect to be disconnected for some time on VM1 before reconnected, so you can’t do it synchronously. So what that means, is VM1 runs some executable/code on VM2 to have VM2 actually disconnect and continue to run Selenium tests locally on VM2, then VM1 polls connecting to VM2 until it connects back and resumes the rest of the automation. This methodology may also require that a portion of Selenium code be run separately/locally on VM2 during the network disconnect, where VM1 will fetch that test result later and merge with the main test results. This is a complicated and potentially flaky approach but is a possible implementation if done correctly.

With Playwright based Browser library you can do this with https://marketsquare.github.io/robotframework-browser/Browser.html#Set%20Offline