Multiple threads in Test Case

in one of my test Cases, i need to check for 2 situations at once and i don’t know which one will manifest first.
Solution - create 2 threads to check in parallel and wait for their finish on the end.
Warning: quick and dirty solution, think before apply.

def t1 = new Thread({
	for(i=0; i<10; i++) println 'Hello 1-'+i
} as Runnable)
def t2 = new Thread({
	for(i=0; i<10; i++) println 'Hello 2-'+i
} as Runnable)

t1.start()
t2.start()

while (t1.alive || t2.alive) {
	Thread.sleep(500)
	// looks like WebUI.delay() - stops whole execution, use Thread.sleep()
	println 'Waiting to end'
}

println 'end'
2 Likes

Upvoted.

That’s pretty sweet, Andrej. I was thinking about using Winium for something recently and realized I may run into a race condition to do what I wanted to do. This might be the solution!

thanx, hope it will help to you