Reputation: 13980
I would like to have an automated test for the following scenario:
I want steps 1. and 3. to be done by Selenium. Question is: how can I do the step 2. as part of the automated test?
Details on the tools and environment:
Couple of solutions I was thinking about:
None of these solutions is ideal for various reasons.
So: did anyone try to solve a similar problem? Would like to hear your solution or alternative ideas, that you think may work. Thanks.
Upvotes: 3
Views: 2495
Reputation: 6058
Stubbing
You'll have to identify what would be the exception thrown and what will be the component that throws it in a real case scenario. You can do that easily, simulate the scenario in your machine and when the exception is thrown, the stack-trace will tell you exactly what component thrown it.
Then you'll have to extend the component that throws the exception and inject it in the proper place and, ultimately, create an API to trigger that exception.
If you think you need a framework to automate this kind of tests, have a look to to Fitnesse.
Simulation
Simulating a real network problem, would be overly complicated and the benefits are not worth the effort in this case (imo).
Anyway... Linux has an excellent built in network emulation layer called netem that allows any kind of seamless interaction with the network traffic. This kernel module is controlled by the tc
command line interface.
It's not very easy to get it right when you want to apply those condition to a single port because you'll have to:
A simple example would be if you want to have 10% packet loss on the whole eth0, in which case you'll use:
tc qdisc change dev eth0 root netem loss 10%
Then you'll have to wrap this functionality in some java controllable way. If I failed on discouraging you, here is a good guide: TrafficControl
Upvotes: 2
Reputation: 3776
You can execute the following commands on windows on cmd to disconnect and reconnect network.
> ipconfig /release
> ipconfig /renew
Using this you can use the Java Runtime
class to execute the command.
Runtime.getRuntime().exec("ipconfig /release");
I have tested this on windows and it works. The Linux equivalent of the cmd commands are as follows
> sudo ifconfig eth0 up
> sudo ifconfig eth0 down
Note that eth0 here is the name of my Ethernet connection. You can list the names of all the connections using
> ifconfig -a
You can look at the following thread to execute bash through Java - How to execute bash command with sudo privileges in Java?
Upvotes: 1