How to add DesiredCapabilities to randomly pick any available browser in selenium grid2 -


i have grid2 setup 7 nodes each node has 1 instance of firefox, chrome , ie.

when running tests don;t want specify particular browser. instead, grid pick random available browser test.

are there desiredcapabilities settings can use make work?

grid uses 1 of below 3 attributes in order narrow down node should new session request routed :

  1. browser name
  2. platform
  3. version

so 1 of these things required test routed node.

there 2 ways in need can fulfilled :

  1. you can build utility locally in test when queried give random browser based desiredcapability object (maybe on round-robin basis) , achieve use-case.
  2. the other way of doing building custom capability matcher [ can refer my blog post learning how , wiring grid ] , in custom capability matcher, build logic of randomly picking browser flavor , try updating incoming requestedcapability map information. mileage here may vary because map seems original map fetched de-serialized json request comes hub, pull off.

personally feel option (1) lot more easy manage , can work grid setup.

updated section : going looking for, here's refinement looking for.

  • (a) build servlet , inject grid hub. can find instructions doing here.
  • (b) in newly built servlet, add logic around these lines

    org.openqa.grid.internal.registry registry = null; list<remoteproxy> freeproxies = new linkedlist<>(); (remoteproxy eachproxy : registry.getallproxies()) {     if (eachproxy.isbusy()) {         continue;     }     //add logic here extract out next usable browser querying     //the proxy's testslot  } 
  • (c) once have injected servlet hub, required make call newly added servlet before exercising option (1) [ utility generates random desiredcapabilities object ], find out next usable browser flavor , have utility generate capability accordingly.

ps : solution require work custom grid wherein have added custom servlet , hence can't work plain vanilla grid setups.


Comments