主机上建立一个hub,在作为slave的多个主机上建立一个或多个node,要执行的项目pom.xml文件中通过设置线程数,hub平均分配任务给下面的node去执行。
比如:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<failIfNoTests>false</failIfNoTests>
<forkCount>5</forkCount>
<resuseForks>false</resuseForks>
<argLine>-Dfile.encoding=UTF-8</argLine>
<systemProperties>
<property>
<name>net.sourceforge.cobertura.datafile</name>
<value>target/cobertura/cobertura.ser</value>
</property>
</systemProperties>
</configuration>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/ServiceAvailability/VirtualPrinterServices/*.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
按以上pom文件的设置,如果hub下有3个node,那么会将5个线程先平均分3个case给3个node,然后把剩下的2个case随机分给其中2个node。最后你能看到2个node上都在多线程跑2个case,最后那个node上只有一个case在跑。
启动Grid建立hub或者node时都需要进入selenium-server-standalone-2.39.0.jar所在目录。通常我们建一个bat文件用来启动Grid server。下面我们将它放在D盘根目录下:
hub.bat: (hub -port 3737需要跟项目中remote controller的server port设置一致)
d:
java -jar selenium-server-standalone-2.39.0.jar -role hub -port 3737
node.bat: (http://10.10.55.32:3737是hub的主机地址)
d:
java -jar selenium-server-standalone-2.39.0.jar -role node -hub http://10.10.55.32:3737/grid/register -port 7001
hub端可以再 http://localhost:3737/grid/console上看到注册的node信息,这样在hub端run的所有case都会在node上的浏览器中去执行。