Using Selenium IDE to act on a Popup - selenium

I have an application that still uses popup windows over Modals, and we need to test the behavior of some of the popups. In my current stage of research it appears the failure occurs on a waitForPopup call. To confirm this, I made a basic HTML page to throw a popup when a link is clicked (easily simulated with IDE)
<html>
<head>
<title>Test Popup</title>
</head>
<body>
Click Me
</body>
<script>
function openwindow() {
var i, l, options = [{
value: 'first',
text: 'First'
}, {
value: 'second',
text: 'Second'
}],
newWindow = window.open("", "popup1", "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
newWindow.document.write("<select onchange='window.opener.setValue(this.value);'>");
for(i=0,l=options.length; i<l; i++) {
newWindow.document.write("<option value='"+options[i].value+"'>");
newWindow.document.write(options[i].text);
newWindow.document.write("</option>");
}
newWindow.document.write("</select>");
}
function setValue(value) {
document.getElementById('value').value = value;
}
</script>
</body>
And the Selenium test case
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://localhost.localdev.com/" />
<title>localpopuptest</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">localpopuptest</td></tr>
</thead><tbody>
<tr>
<td>click</td>
<td>id=click_me</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=click_me</td>
<td></td>
</tr>
<tr>
<td>waitForPopUp</td>
<td>popup1</td>
<td>30000</td>
</tr>
<tr>
<td>assertTitle</td>
<td></td>
<td>Test Popup</td>
</tr>
</tbody></table>
</body>
</html>
This seems to be a common issue, is there a better way to track and assert popup windows?

Check this out:
click | id=click_me
selectWindow | popup1
select | //select | Second
If your popup has a dynamic content you can just add:
waitForElementPresent | //select
after selectWindow.

Related

Add custom column to DataTable Export

When exporting my dataTable to a PDF I'd like to add an extra blank column that doesn't exist on the dataTable itself. All it needs is the headline and a blank field for each row. Is that possible somehow?
I was able to add a custom column by adding the following to my exportOptions in my dataTabel config:
customizeData: function (data) {
data['header'].push('Custom Field');
$.each(data['body'], function(key, row) {
row.push('');
});
}
You can add an extra empty column to the PDF by manipulating the PDFMake document structure.
You can access this structure using the pdfHtml5.customize function.
A simple demo:
$(document).ready(function() {
$('#example').DataTable({
dom: 'Bfrtip',
buttons: [{
extend: 'pdf',
customize: function (pdf) {
addExtraColumn(pdf);
}
}
]
});
});
function addExtraColumn(pdf) {
pdf.content[1].table.body.forEach(function(row, idx) {
let newCell = structuredClone(row[0]);
newCell.text = idx === 0 ? "New Heading" : "";
row.push( newCell );
console.log( row );
})
};
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Export to PDF</title>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/2.2.3/css/buttons.dataTables.min.css"/>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/2.2.3/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/2.2.3/js/buttons.html5.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://datatables.net/media/css/site-examples.css">
</head>
<body>
<div style="margin: 20px;">
<table id="example" class="display nowrap dataTable cell-border" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<tr>
<td>Adelaide Nixon</td>
<td>One</td>
</tr>
<tr>
<td>Bruna Nash</td>
<td>Two</td>
</tr>
</tbody>
</table>
</div>
</body>
So, if you start with a table which looks like this:
Then the PDF will look like this:
From there, you may want to further customize the PDF - for example, by drawing lines around every cell, and so on.
You can read the PDFMake documentation for tables, and see examples for more guidance.

Selenium IDE 2.9.1 is not showing the selenium script after recording

I just installed selenium IDE 2.9.1 and recorded a testcase. But when inspect the source, It is showing only the HTML, not selenium script.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="https://www.google.co.in/" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/?gws_rd=ssl</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=Passwd</td>
<td>arunkojndfjn</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=signIn</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
What to do to get the selenium script ? Thanks.
Convert a selenium IDE script into one that can be run in Webdriver isn't done by viewing the file, as the file itself is written in a selenium specific format of HTML. You need to use the options within selenium IDE itself. If you go to "File > Export Test Case as" you will get a list of various languages you can export the test as.

SQL CFoutput help, not processing when opening webpage

I am currently learning SQL. On my CFM page I have entered all the information from the instructions my professor has given us. I have even compared to other students to try and figure out what is wrong, but their pages look like mine. Please help me figure out what I have done wrong. Thanks.
This is the webpage link http://pretendcompany.com/jaedenemployees.html
Error:
72777A, on line 66, column 32, is not a valid identifer name. The CFML
compiler was processing: The body of a CFOUTPUT tag beginning on line
62, column 3.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="YOUR NAME HERE" />
<title>USU MIS 2100</title>
<style type="text/css" media="all">
td {
align:center;
width:955;
border:none;
text-align:center;
vertical-align:top;
height:40px;
}
table.center{
margin:auto;
}
h1{
font-size:26px;
color:#001F3E;
}
h2{
font-size:20px;
color:#ffffff;
}
img{ text-align:center;
}
td.photo{
margin:auto;
}
</style>
</head>
<body>
<table class="center">
<tr>
<td ><img src="images/header2_usu.jpg" width="755" height="265" alt="usu" /></td>
</tr>
<tr>
<td style="height:900;background-color:#D7D9D9;padding-top:50px;">
Employees by Department at Pretend Company, Inc.</font></p>
<h1>Jaeden Harris</h1>
<CFQUERY name="jaeden" datasource="employeedatasource">
select Accounting,Administrative,Advertising,Payroll,Sales
from employees
where DepartmentName in(#PreserveSingleQuotes(form.SelectDepts)#)
</CFQUERY>
<!--Place opening CFOUTPUT here -->
<CFOUTPUT query="jaeden">
<table style="width:500;border:none;" class="center">
<tr style="background-color:#72777A;">
<td colspan="2"><h2> #DepartmentName# Employees </h2></td>
</tr>
<tr>
<td style="width:250;text-align:left;">Employee:#FirstName# #MiddleName# #LastName#
<p>Title: #Title#
<p>Email: #EmailName# #pretendcompany.com
<p>Contact Number: #WorkPhone#
</p>
</td>
<td style="width:140px;vertical-align:middle;" class="photo"><!--Reference Photograph field here --> </td>
</tr>
</table>
</CFOUTPUT>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
You are within a CFOUTPUT, therefor anything with # signs gets evaluated, including the style background-color:#72777A;. Either escape those with a double hash: background-color:##72777A; or move the style out of your CFOUTPUT.
Since you already have a section for your CSS, it may be wise for you to move all your table styles from inline with the HTML to the top and just apply classes to your elements.

Selenium IDE: Bind mouseOver() on dynamically generated div

i have a div element which is created via JS on the fly.
<div id='menu_item_0'>foo</div>
Now my Selenium IDE locator is able to access this element with various selectors, but whatever event like e.g. mouseOver or clickAt etc I use, they all seem to get ignored.
I could of course wirte some script an fire this, but i want to test exactly the mouseover by a mouse and not dispatch it by myself.
Anyone has an idea on this? The recorder does not record this too.
Thanks & Regards
Can you show us the complete html and js ?
Here's a test code I've run with success. Does it match what you're trying to do ?
The HTML :
<html>
<body>
<script>
function insert(){
var container = document.getElementById("container")
var newdiv = document.createElement('div');
newdiv.setAttribute('id','menu_item_0');
newdiv.innerHTML = 'Added the element';
newdiv.onmouseover = function(){
newdiv.innerHTML = 'I feel tickled';
}
newdiv.onclick = function() {
newdiv.innerHTML = 'I feel clicked';
}
container.appendChild(newdiv);
}
setTimeout(insert,2000);
</script>
<div id="container"></div>
</body>
</html>
And the selenium test (just save this in a .html file and open it from Selenium IDE) :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="file:///G:/dev/proj/test-selenium-ide/" />
<title>test1</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">test1</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>index.html</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>menu_item_0</td>
<td>2500</td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>menu_item_0</td>
<td></td>
</tr>
<tr>
<td>mouseOver</td>
<td>menu_item_0</td>
<td></td>
</tr>
<tr>
<td>assertText</td>
<td>menu_item_0</td>
<td>I feel tickled</td>
</tr>
<tr>
<td>clickAt</td>
<td>menu_item_0</td>
<td></td>
</tr>
<tr>
<td>assertText</td>
<td>menu_item_0</td>
<td>I feel clicked</td>
</tr>
</tbody></table>
</body>
</html>

Having trouble getting the selenium command line to run HTML tests and record output, then exit w/ status that reflects test result

I am having trouble running selenium on my Mac so that it runs a simple suite with one simple test (see sections 'TEST CASE' and 'TEST SUITE', below) using the following command line:
java -jar lib/selenium-server.jar -timeout 10 -log server.log -browserSideLog browser.log -debug -htmlSuite '*firefox' http://google.com `pwd`/suite3 `pwd`/selenium.html
My problem is that i don't get a non-zero return code as expected when tests fail, and also, i don't see any reports.
I have tried the following variants:
Using the given suite and testcase files either:
specify -timeout option (ends drastically with no reports being written), or
do not specify the -timeout option.
without the time out option the selenium server never shuts down... even though the help documentation says:
Run a single HTML Selenese (Selenium Core) suite and then exit
immediately, using the specified browser (e.g. "*firefox") on the
specified URL (e.g. "http://www.google.com").
To get around the hang i added an extra selenium command to the test case to force shut down of the server, as follows:
.... previous commands ...
<tr>
<td>open</td>
<td>http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer</td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>
This did eliminate the hang. The browser shut down and the process terminated.. but i got no test results, and my exit code was (incorrectly) zero... not
non-zero as i would have expected.
TEST SUITE (this needs to be saved with the name 'suite3' )
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://google.com" />
<title>testcase3</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">testcase3</td></tr>
</thead>
<tbody>
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>xbout Google</td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>
TEST CASE
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://google.com" />
<title>testcase3</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">testcase3</td></tr>
</thead>
<tbody>
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>xbout Google</td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>
Thanks in advance to whoever can give me a clue to solve this !
- chris
Our colleague in Beijing, Chenyun Xiao, figured out the trick here. If you rename both the suite and testcase file so they have .html extensions (and u make sure that the ref from suite to testcase is updated to reflect the new name for the test case file) then everything will work as expected.. Thanks, Chenyun – Chris Bedford 1 min ago
I suggest to use java for your testsuite and testcase.
I encountered coded vanishes when dealing with the html selenium code.
I'm sure there is a solution using Selenium Server (formerly RC) but I don't know it off-hand. And I'm on a project that keeps me from researching it.
PushToTest TestMaker has a great command-line interface to run Selenese Table Format scripts in a desktop, grid, or cloud environment. Check out the tutorial at http://www.pushtotest.com/web-testing-with-selenium-pushtotest to see how it all fits together.
-Frank