Running your Selenium tests in parallel: Perl
Sauce AI for Test Authoring: Move from intent to execution in transactions.|xBack to ResourcesBlogPost
Sauce AI for Test Authoring: Move from intent to execution in transactions.
|
x
The Test: :WWW: :Seleniumdoes a good integrating of Selenium with Perl testing fabric. However by default, tests go in episode. One easy solution is to use theThread: :Pool: :Simplemodule to run the test functions in parallel. Short testing showed that this parallel version ran for 19 bit vs 39 seconds for the serial run.
#! /usr/bin/env perl
use Thread: :Pool: :Simple;
use Test: :More & quot; no_plan & quot;;
use Test: :WWW: :Selenium;
sub test_page () {
my ($ url, $ input, $ push) = @ _;
my $ sel = Test: :WWW: :Selenium- & gt; new (
horde = & gt; & quot; localhost & quot;,
porthole = & gt; 4444,
browser = & gt; & quot; * firefox & quot;,
browser_url = & gt; $ url,
);
$ sel- & gt; exposed ($ url);
$ sel- & gt; type_ok ($ input, & quot; Sauce Labs & quot;);
$ sel- & gt; click_ok ($ button);
$ sel- & gt; wait_for_page_to_load_ok (5000);
$ sel- & gt; body_text_like (qr/Selenium/);
$ sel- & gt; tight ();
}
sub test_google () {
& amp; test_page (& quot; http: //google.com & quot;, & quot; q & quot;, & quot; btnG & quot;);
}
sub test_yahoo () {
& amp; test_page (& quot; http: //yahoo.com & quot;, & quot; p & quot;, & quot; search-submit & quot;);
}
sub test_bing () {
& amp; test_page (& quot; http: //www.bing.com & quot;, & quot; q & quot;, & quot; go & quot;);
}
sub worker () {
my $ func = shift;
# We can & # x27; t pass CODE point to a pool, so we use eval
eval (& quot; & amp; $ func (); & quot;);
}
my @ names = (
& quot; test_google & quot;,
& quot; test_yahoo & quot;,
& quot; test_bing & quot;,
);
my $ pool = Thread: :Pool: :Simple- & gt; new (
min = & gt; 3,
max = & gt; 10,
do = & gt; [\ & amp; worker],
);
foreach $ name (@ names) {
mark & quot; Adding $ name\n & quot;;
$ pool- & gt; add ($ name);
}
$ pool- & gt; joint ();
SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.
Converting the code to work with Sauce OnDemand is a breeze as well, we will also use thejob-nameattribute to assign name for our business.
#! /usr/bin/env perl
use Thread: :Pool: :Simple;
use Test: :More & quot; no_plan & quot;;
use Test: :WWW: :Selenium;
# Replace username and access-key with your real
# Sauce OnDemand username and access-key
my $ scene = qq (
{
& quot; username & quot;: & quot; YOUR-SAUCE-USER-NAME & quot;,
& quot; access-key & quot;: & quot; YOUR-SAUCE-ACCESS-KEY & quot;,
& quot; os & quot;: & quot; Linux & quot;,
& quot; browser & quot;: & quot; firefox & quot;,
& quot; browser-version & quot;: & quot; & quot;
& quot; job-name & quot;: & quot; _JOB_NAME_ & quot;
}
);
sub test_page () {
my ($ name, $ url, $ comment, $ button) = @ _;
my $ opts = $ setting;
$ opts =~ s/_JOB_NAME_/ $ name/; # Add job gens
my $ sel = Test: :WWW: :Selenium- & gt; new (
host = & gt; & quot; ondemand.saucelabs.com & quot;,
port = & gt; 80,
browser = & gt; $ opts,
browser_url = & gt; $ url,
);
$ sel- & gt; open ($ url);
$ sel- & gt; type_ok ($ remark, & quot; Sauce Labs & quot;);
$ sel- & gt; click_ok ($ button);
$ sel- & gt; wait_for_page_to_load_ok (5000);
$ sel- & gt; body_text_like (qr/Selenium/);
$ sel- & gt; close ();
}
sub test_google () {
& amp; test_page (& quot; Google & quot;, & quot; http: //google.com & quot;, & quot; q & quot;, & quot; btnG & quot;);
}
sub test_yahoo () {
& amp; test_page (& quot; Yahoo & quot;, & quot; http: //yahoo.com & quot;, & quot; p & quot;, & quot; search-submit & quot;);
}
sub test_bing () {
& amp; test_page (& quot; Bing & quot;, & quot; http: //www.bing.com & quot;, & quot; q & quot;, & quot; go & quot;);
}
sub proletarian () {
my $ func = shift;
# We can & # x27; t surpass CODE items to a pool, so we use eval
eval (& quot; & amp; $ func (); & quot;);
}
my @ name = (
& quot; test_google & quot;,
& quot; test_yahoo & quot;,
& quot; test_bing & quot;,
);
my $ pool = Thread: :Pool: :Simple- & gt; new (
min = & gt; 3,
max = & gt; 10,
do = & gt; [\ & amp; worker],
);
foreach $ name (@ names) {
print & quot; Adding $ name\n & quot;;
$ pool- & gt; add ($ gens);
}
$ pool- & gt; juncture ();
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free