Archive
Resolving “Couldn’t open app window; is the pop-up blocker enabled?” Selenium error in IE 10
Need to setup my Linux machine(master) to remotely access a Windows 8 machine(slave) with Internet Exporer 10 browser that will run my Selenium scripts.
master – machine where Selenium scripts, browser configurations are saved; one that will be sending requests to run the scripts
slave – machine where Selenium scripts will be run using a different platform (OS and browser); one that will accept the request to run the scripts
To do this, I configure the browser file from the master machine:
# for Internet Explorer our $sel = Test::WWW::Selenium->new( host => "Windows Machine IP", port => 4445, browser => "*iexplore", browser_url => "application URL" );
From the slave machine, I needed to install the following:
- Java SE Runtime Environment 1.7
- download latest Selenium Server from SeleniumHQ
To prepare the slave machine to accept the request, launch selenium server from the terminal using the same port set in the master machine:
java -jar selenium-server-standalone-2.23.1 -port 4445
To send request from the master machine, you may use “spec”, “rake” command depending on how you organized your test files. However after executing the command to run the scripts from the master machine, an error was encountered in the slave machine - “Couldn’t open app window; is the pop-up blocker enabled?”
# for Internet Explorer our $sel = Test::WWW::Selenium->new( host => "Windows Machine IP", port => 4445, browser => "*iexploreproxy", browser_url => "application URL" );
Perl-Selenium Helpful String Manipulations
Below are the string functions I found helpful during scripting in my current project using Selenium in Perl language:
Split(/PATTERN/,EXPR)
- Splits the string EXPR into a list of strings based on given PATTERN and returns that list.
# Scenario: Clicking Email link opens new window. Verify new location/URL displayed is correct
# Email element: <a onclick=”window.open(‘http:test.url’,'EMAIL’,'width=730,height=450,status=yes,toolbar=no,menubar=no,location=no’);” style=”color: rgb(38, 6, 2); font-size: 11px; text-decoration: underline;” href=”javascript: void(0);”>Email</a>
my $href = $sel->get_attribute("xpath=//html/body/div[2]/div[2]/div[2]/table/tbody/tr/td[2]/div[3]/a/\@onclick");
# $href = "window.open('http:test.url','EMAIL','width=730,height=450,status=yes,toolbar=no,menubar=no,location=no');"
my @url = split(/'+/, $href);
# @url = ['window.open(' , 'http:test.url' , ',' , 'EMAIL' , ',' , 'width=730,height=450,status=yes,toolbar=no,menubar=no,location=no' , ');' ]
Substr(EXPR,OFFSET,LENGTH)
- Extracts a substring out of EXPR and returns it based on defined OFFSET and LENGTH
# Scenario: Get the numeric value from the Total distance string element
my $str = $sel->get_text("css=div.olPopupContent>div.mainbubblecontent>div.mainbubbletabcontent>div.activetabcontent>div:nth-child(5)");
# $str = "Total distance: 100.25 miles";
my $distance = substr($str,16,5);
# $distance = '100.25';
Match (m/PATTERN/)
- match a string with a regular expression pattern
my $str = "Total distance: 100.25 miles";
if ($str =~ m/ \d*.\d* miles/) {
print "Pass";}
else{
print "Fail";}
Cmp_ok( $got, $op, $expected, $test_name )
– Test::More function that allows you to compare two arguments using any binary perl operator.
my $str = $sel->get_text("css=#panel > #collection_maneuvers > thead > tr > th");
# $str = "Total distance\: 100.25 miles"
cmp_ok($str, "=~", m/Total distance\: \d*.\d* miles/, "Verify estimated mileage is displayed");
Like( $got, qr/expected/, $test_name )
– Another Test::More function that evaluates any expression against a regular expression
my $str = $sel->get_text("css=#panel > #collection_poi > thead > tr.poi > th");
# $str = "5 locations found in your area"
like($str, qr/\d* locations found in your area/, "Verify number of locations is displayed");
Also came across this Perl documentation link (http://perldoc.perl.org) which is direct and comprehensive.
Selenium RC to test unsecured connection HTTPS
It’s inevitable for software testers to run test in an environment with self-signed SSL certificates. This became one of my dilemma when trying to run my Selenium scripts in an HTTPS environment and was always prompted with “This Connection is Untrusted” error.
I have an existing Firefox Profile solely for Selenium, if you don’t have one, you can check this post. Was able to resolve this issue by doing the following:
- Launch Profile Manager by typing “firefox -ProfileManager -no-remote” in your terminal (Linux user)
- Select Selenium profile then Start Firefox
- Access your web application URL in HTTPS
- Accept the SSL Certification:
- Click “I Understand the Risks”
- Click “Add Exception”
- Click “Get Certificate”
- Make sure “Permanently store this exception” tickbox is checked
- Click “Confirm Security Exception”
- After successfully directed to the web application page, close Firefox
- Go to Selenium Profile folder ( in my case /home/girlie/.mozilla/firefox/selenium )
- Delete all files except for cert_override.txt and cert8.db files.
From here on, I rerun my Selenium scripts and didn’t encountered the “This Connection is Untrusted” error anymore
Selenium-Ruby Installations in Linux
In relation to my previous post on Selenium and Ruby setup in Windows, here’s an installation guide for Linux peeps:
1. Install JRE
- In your terminal type: sudo apt-get install sun-java6-jre
- To verify type: java -version
Note: Java version should be 1.5 or higher versions
2. Install Ruby
- In your terminal, type: sudo apt-get install ruby
- To verify type: ruby –version
Note: ruby 1.8.7 works with rspec version <= 1.3.1
3. Install Rubygems
- From the terminal, type: sudo apt-get install rubygems OR you can follow this tutorial Installing RubyGems
- To verify type: gem –version
4. Install other useful gems
- Rake ( to create a task that runs set of tests )
- Type: sudo gem install rake
- To verify type: rake –version
- Selenium-client ( API to drive Selenium tests from Ruby )
- Type: sudo gem install selenium-client -v 1.2.18
- To verify type: gem list selenium-client
Note: selenium-client 1.2.18 works with rspec version 1.2.8
- Rspec ( to define executable examples of the expected behaviour of your code )
- Type: sudo gem install rspec -v 1.2.8
- To verify type: spec –version
- Faker ( to easily generate fake data: names, addresses, phone numbers, etc. )
- Type: sudo gem install faker
- To verify type: gem list faker
Basic CSS Locators
Sample HTML chunk:
<div id=”page”>
<ul id=”index”>
<li>
<div class=”actions”>
<h3>Test 01</h3>
<a class=”1″>
<a class=”2″>
</div>
<li>
<div class=”actions”>
<h3>Test 02</h3>
<a class=”1″>
<a class=”2″>
</div>
Sample CSS Locators:
| Element | Locators | |
| 1 | Page | css=div#page |
| css=div[id=page] | ||
| id=page | ||
| 2 | Index | css=div#page>ul#index |
| css=div[id=page] ul[id=index] | ||
| css=ul#index | ||
| 3 | Actions | css=div.actions |
| css=div[class=actions] | ||
| 4 | First a child of first li element | css=ul#index>li>div.actions>a:first-child |
| css=ul[id=index] li div[class=action] a:first-child | ||
| css=ul#index>li>div.actions>a | ||
| 5 | Last/Second a child of second li element | css=ul#index>li:nth-child(2)>div.actions>a:last-child |
| css=ul#index>li:nth-child(2)>div.actions>a:nth-child(2) | ||
| 6 | Heading containing text | css=h3:contains(‘Test 01′) |
For a comprehensive list of CSS Selector Syntax, check this link: http://www.w3.org/TR/css3-selectors/
<li>
<div class=”action_buttons”><a title=”Show Arthur C. Ortiz” href=”/people/arthur-c-ortiz” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Arthur C. Ortiz” href=”/people/arthur-c-ortiz/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Arthur C. Ortiz” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Arthur C. Ortiz?” href=”/people/arthur-c-ortiz” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Arthur C. Ortiz</h3></li>
<li>
<div class=”action_buttons”><a title=”Show Carlos Tucker” href=”/people/carlos-tucker” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Carlos Tucker” href=”/people/carlos-tucker/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Carlos Tucker” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Carlos Tucker?” href=”/people/carlos-tucker” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Carlos Tucker</h3></li>
<li>
<div class=”action_buttons”><a title=”Show Catherine Rose” href=”/people/catherine-rose” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Catherine Rose” href=”/people/catherine-rose/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Catherine Rose” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Catherine Rose?” href=”/people/catherine-rose” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Catherine Rose</h3>
</li>
<li>
<div class=”action_buttons”><a title=”Show Christina Sims” href=”/people/christina-sims” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Christina Sims” href=”/people/christina-sims/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Christina Sims” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Christina Sims?” href=”/people/christina-sims” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Christina Sims</h3>
</li>
<li>
<div class=”action_buttons”><a title=”Show Christopher R. Young” href=”/people/christopher-r-young” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Christopher R. Young” href=”/people/christopher-r-young/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Christopher R. Young” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Christopher R. Young?” href=”/people/christopher-r-young” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Christopher R. Young</h3>
</li>
<li>
<div class=”action_buttons”><a title=”Show Cynthia Fuller” href=”/people/cynthia-fuller” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Cynthia Fuller” href=”/people/cynthia-fuller/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Cynthia Fuller” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Cynthia Fuller?” href=”/people/cynthia-fuller” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Cynthia Fuller</h3>
</li>
<li>
<div class=”action_buttons”><a title=”Show Debra Wagner” href=”/people/debra-wagner” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Debra Wagner” href=”/people/debra-wagner/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Debra Wagner” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Debra Wagner?” href=”/people/debra-wagner” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Debra Wagner</h3>
</li>
<li>
<div class=”action_buttons”><a title=”Show Dennis Matthews” href=”/people/dennis-matthews” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Dennis Matthews” href=”/people/dennis-matthews/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Dennis Matthews” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Dennis Matthews?” href=”/people/dennis-matthews” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Dennis Matthews</h3>
</li>
<li>
<div class=”action_buttons”><a title=”Show Diana Burton” href=”/people/diana-burton” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Diana Burton” href=”/people/diana-burton/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Diana Burton” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Diana Burton?” href=”/people/diana-burton” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Diana Burton</h3>
</li>
<li>
<div class=”action_buttons”><a title=”Show Edward Torres” href=”/people/edward-torres” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Edward Torres” href=”/people/edward-torres/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Edward Torres” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Edward Torres?” href=”/people/edward-torres” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Edward Torres</h3>
</li>
</ul>
Run your RC server via Rakefile
Gone tired of starting your selenium server by typing,
“java -jar selenium-server.jar"
from your console or if you’re luckier create a batch file then run it to start your server...
Here’s a more powerful tool to do it. Utilizing the selenium-client ruby gem, first you need to create a rakefile and define the tasks that you want to do. For instance we want to tell our rake to do the following tasks:
1. Start selenium server,
2. Stop selenium server, and
3. Restart selenium server
require 'rubygems' require 'selenium/rake/tasks' # use selenium rc rake tasks that are bundled with the selenium-client gem SELENIUM_RC_JAR = Dir[File.dirname(__FILE__) + "/selenium-server*.jar"].first # Start selenium server task Selenium::Rake::RemoteControlStartTask.new(:'rc:start') do |rc| rc.port = 4444 rc.timeout_in_seconds = 3 * 60 rc.background = true rc.wait_until_up_and_running = true rc.jar_file = SELENIUM_RC_JAR rc.additional_args << " -multiWindow -firefoxProfileTemplate FirefoxProfile" end # Stop selenium server task Selenium::Rake::RemoteControlStopTask.new(:'rc:stop') do |rc| rc.host = "localhost" rc.port = 4444 rc.timeout_in_seconds = 3 * 60 end # Restart selenium server task desc "Restart Selenium Remote Control" task :'rc:restart' do Rake::Task[:"rc:stop"].execute [] rescue nil Rake::Task[:"rc:start"].execute [] end
In your console go to the root folder where your rake file is saved, type
“rake -T” or “rake –task”
D:\Projects>rake -T
Console will list all available tasks defined in the rake:
(in D:/Projects)
rake rc:restart # Restart Selenium Remote Control
rake rc:start # Launch Selenium Remote Control
rake rc:stop # Stop Selenium Remote Control running
From this list you can restart/start/close the server by simply invoking the commands e.g. rake rc:start
Selenium and Ruby setup in Windows
Newbie in Ruby? Never heard Selenium? Had a reformat?
No sweat! Here’s a list of requirements to set up Selenium and Ruby in your Windows machine.
SELENIUM Remote-Control (RC )
–> is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser.
- get it here
- extract the file anywhere in you local machine
JAVA
–> Requirement to run the selenium server, should be 1.5 or later version
- get it here
- install Java and configure your PATH environment variable correctly.
- from the console, you can verify the installation by typing: java -version
SELENIUM RC RUBY CLIENT DRIVER
- requires Ruby
- recommended way to install: Ruby 1.8.6 One-Click Installer
- upgrade to latest version by getting the latest binary files of Ruby 1.8.7
Rubygems
- get the latest rubygem distribution as tgz or zip from here
- extract the archive to your desired directory
- 2 ways to install ruby:
from the console, go to the extracted directory then type: ruby setup.rb
from your explorer, go to the extracted directory and double click setup.rb file
- install the ruby client driver as a rubygem by typing: gem install <ruby gem>
gem install selenium-client
- install other gems that will be useful in your testing:
gem install rspec -v=1.2.6
gem install syntax
gem install faker
BDoc documentation
–> guide for all your rubygems documentations
- from the console type: gem install aptinio-bdoc
- then save the doc to your local, from the console type: bdoc //[path]
To get scripts or file from a repository through Git
- from the console, install github, bash or gui OpenInGitGui-2.0.zip
- generate an SSH rsa, type: $ ssh-keygen -t rsa
- copy the generated id_rsa pub
- paste it on the personal settings of ur public_key
- then clone




Recent Comments