I'm running an HTML test suite as such:
java -jar /var/lib/selenium/selenium-server.jar -browserSessionReuse -htmlSuite *firefox http://$HOST ./test/selenium/html/TestSuite.html ./target/selenium/html/TestSuiteResults.html
Is there a way I can run all test suites in a directory, or create a test suite of test suites?
I'm very new to Selenium and really only Selenium2. I'm using "TestNG" as my test framework, and it does support suites and suites of suites using an xml file that specifies which tests carrying a particular annotation are part of the suite.
If running suites of suites is what you are looking for, and you are using Java exclusively (TestNG does not, as I understand it, support anything other than Java), then you may find what you're looking for.
I created a grails script to create a super-testsuite automatically. Needing to modify test suites is one more step in adding a test, and each level of barrier increases the likelihood of developers refusing to write tests.
import groovy.io.FileType
includeTargets << grailsScript("Init")
target(main: "Auto-generates the TestSuite.html file needed for selenium based on selenium html tests in test/selenium/html/**") {
File testSuiteOutputFile = new File("test/selenium/html/TestSuite.html")
testSuiteOutputFile.delete()
String testRows = buildTestRows()
testSuiteOutputFile <<
"""
<?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>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<title>Test Suite</title>
</head>
<body>
<table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium"><tbody>
<tr><td><b>Test Suite</b></td></tr>
$testRows
</tbody></table>
</body>
</html>
"""
}
private def buildTestRows() {
String testRows = ""
List<File> testFiles = getAllTestFilesInSeleniumDirectory()
testFiles.each { file ->
def relativePath = buildFilePathRelativeToTestSuite(file)
println "Adding $relativePath to TestSuite"
testRows += "<tr><td><a href='${relativePath}'>${file.name}</a></td></tr>"
testRows += "<tr><td><a href='clearCache.html'>Clear Cache</a></td></tr>"
}
testRows
}
private List<File> getAllTestFilesInSeleniumDirectory() {
File testsDirectory = new File("test/selenium/html")
def files = []
testsDirectory.eachFileRecurse(FileType.FILES) { files << it }
files
}
private String buildFilePathRelativeToTestSuite(File file){
File parentDirectory = new File("test/selenium/html")
String relativePath = file.name
file = file.parentFile
while( file != parentDirectory ){
relativePath = file.name + "/" + relativePath;
file = file.parentFile
}
relativePath
}
setDefaultTarget(main)
Look at Selunit. It provides a Maven plugin to execute Selenese suites in batch and transforms reports to Junit format. The last is very usefull for integration of test execution into a CI server like Jenkins, which generates nice charts and notifies in case of test errors.
Related
Background:
I am trying to scrape information from a link but I cannot seem to get the HTML source code to further parse it.
Link:
https://www.realestate.com.au/buy/property-house-in-vaucluse,+nsw+2030/list-1?source=refinement
Code:
chrome_options = webdriver.ChromeOptions()
preferences = {"safebrowsing.enabled": "false"}
chrome_options.add_experimental_option("prefs", preferences)
chrome_options.add_argument('--disable-gpu')
browser = webdriver.Chrome('link_to_chrome_driver.exee', chrome_options=chrome_options)
url = property_link
print(url)
browser.get(url)
delay = 20 # seconds
try:
WebDriverWait(browser, delay).until(EC.element_to_be_clickable((By.CSS_SELECTOR,'rui-button-brand pagination__link-next')))
time.sleep(10)
except:
pass
html = browser.page_source
soup = BeautifulSoup(html)
print(soup)
Output:
<html lang="en"><head>
<meta charset="utf-8"/>
<link href="about:blank" rel="shortcut icon"/>
</head>
<body>
<script src="/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/j.js"></script>
<script src="/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/f.js"></script>
<script src="/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/fingerprint/script/kpf.js?url=/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/fingerprint&token=d33b4707-4c3a-5fbb-8de6-b6889ed26c7d"></script><div></div>
</body></html>
Question:
I don't understand what is going wrong - but when I manually load the site from the any browser - the html script is significantly different. However parsing the site with selenium/bs is far too problematic - What am I doing wrong?
Your CSS selector is incorrect.
Try to edit the css selector as below:
.rui-button-brand.pagination__link-next
Refer to: https://www.w3schools.com/cssref/css_selectors.asp
I'm trying to run this simple test on RIDE, but I cannot figure out it's failing without giving me any specific details:
Ride Log
command: pybot.bat --argumentfile c:\users\user\appdata\local\temp\RIDEe2en9t.d\argfile.txt --listener C:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py:49555:False C:\Python27\Scripts\test\Login\login_suite.robot
========================================================================================================================================================================
Login Suite
========================================================================================================================================================================
login_user | FAIL |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="/assets/displayhelpservlet.css" media="all"/>
<link href="/assets/favicon.ico" rel="icon" type="image/x-icon" />
<script src="/assets/jquery-3.1.1.min.js" type="text/javascript"></script>
<script src="/assets/displayhelpservlet.js" type="text/javascript"></script>
<script type="text/javascript">
var json = Object.freeze('{"consoleLink":"/wd/hub","type":"Standalone","version":"3.11.0","class":"org.openqa.grid.web.servlet.DisplayHelpServlet$DisplayHelpServletConfig"}');
</script>
</head>
<body>
<div id="content">
<div id="help-heading">
<h1><span id="logo"></span></h1>
[ Message content over the limit has been removed. ]
</span>
</p>
<p>
Happy Testing!
</p>
</div>
<div>
<footer id="help-footer">
Selenium is made possible through the efforts of our open source community, contributions from
these people, and our
sponsors.
</footer>
</div>
</div>
</body>
</html>
Selenium server is started (standalone-3.11.0)
Python version 2.7
Environment Path is set Python27/Scripts
Here is the test code:
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
login_user
SeleniumLibrary.Open Browser Google.com googlechrome
Maximize Browser Window
Title Should Be Google
The webdriver for Chrome is also set in Scripts folder, but I've tried it with Firefox as well and got the same result.
EDIT:
so i have tried with this code
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
login_user
SeleniumLibrary.Open Browser https://google.com googlechrome
Maximize Browser Window
Title Should Be Google
If you have
Selenium
Robot Framework
RIDE (for running robot files)
Chrome
The only thing you have to do is download chromedriver.
https://chromedriver.storage.googleapis.com/index.html?path=2.38/
After you have download the chromedriver put it to a folder and add it to your path.
The way i have done after unzipping chromedriver
Ubuntu:
sudo mv chromedriver /usr/local/bin/
sudo chown root:root /usr/local/bin/chromedriver
Windows:
put chromedriver.exe into a folder in this example C:\drivers\
Press Windows button on your keyboard and type Edit the system environment variables
Under Advanced tab, Click Environment Variables
List item
Under System Variables find "Path" and click on Path and Edit button
Click new and add the path where you have put the chromedriver
in this example C:\drivers\chromedriver
I want to run cucumber feature file from java code.
currently we are running form JUnit Runner
package com.compareglobalgroup.testscript;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
#CucumberOptions(features = { "src/test/resources/feature/BB" }, glue = { "com.compareglobalgroup.stepdefs.BB",
"com.compareglobalgroup.cucumber.hooks" }, plugin = {
"json:cucumberreport/json/cucumberreport.json" }, tags = { ""
+ "#Test" })
public class TestRunnerBB extends AbstractTestNGCucumberTests {
}
I don't want to use this instead I want to run this using java program because I want to pass tags at run time from command line or jenkins.
Call the static main method of Main class in the package cucumber.api.cli that corresponds to running cucumber from the command line.
public static void main(String[] args) throws Throwable {
Main.main(new String[]{"-g", "classpath to step definition file", "Full path to feature file"});
// My stepdefinition is inside java package at cucumber.sample.test
// My feature file is inside src/test/resources/features/featurefile.feature
}
For additional parameters like tags or plugin use "-t","#Tags". Important the feature file path has to be the last option.
BTW - In the your example you are running with a TestNG cucumber runner.
I would recommend qaf-gherkin where you don't need to use junit or other runner. All you need to specify step provider package and feature file(s) or dir to run. For example:
<test name="Gherkin-QAF-Test">
<parameter name="step.provider.pkg" value="com.qmetry.qaf.automation.impl.step.qaf" />
<parameter name="scenario.file.loc" value="resources/features" />
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
You can walk through qaf-step-by-step-tutorial
This is ridiculous. Why does it happen??
HTML source code:
<!DOCTYPE html>
<html>
<head>
<title>WTF</title>
<meta charset="utf-8" />
</head>
<body id="b">
<map name="Map" id="Map">
<area
id="clickhereyoustupidselenium" alt="" title=""
href="javascript:document.getElementById('b').innerHTML = 'adsf'"
shape="poly" coords="51,29,155,25,247,87,156,129,52,132,23,78,84,56,104,35" />
<img usemap="#Map" src="http://placehold.it/350x150" alt="350 x 150 pic">
</map>
</body>
</html>
Selenium test code:
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element
from selenium.webdriver.common.by import By
class SeleniumTest(StaticLiveServerTestCase):
#classmethod
def setUpClass(cls):
super(SeleniumTest, cls).setUpClass()
cls.selenium = WebDriver()
#classmethod
def tearDownClass(cls):
cls.selenium.quit()
super(SeleniumTest, cls).tearDownClass()
def test_wtf(self):
self.selenium.get('%s%s' % (self.live_server_url, '/'))
self.selenium.find_element_by_id('clickhereyoustupidselenium').click()
WebDriverWait(self.selenium, 100).until(text_to_be_present_in_element((By.TAG_NAME, "body"), "adsf"))
self.assertEqual(self.selenium.find_element_by_tag_name('body').text, 'adsf')
The test passes beautifully.
OK, so now let's replace src="http://placehold.it/350x150" with a different image, let's say this one: src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/POL_location_map.svg/500px-POL_location_map.svg.png":
<!DOCTYPE html>
<html>
<head>
<title>WTF</title>
<meta charset="utf-8" />
</head>
<body id="b">
<map name="Map" id="Map">
<area
id="clickhereyoustupidselenium" alt="" title=""
href="javascript:document.getElementById('b').innerHTML = 'adsf'"
shape="poly" coords="51,29,155,25,247,87,156,129,52,132,23,78,84,56,104,35" />
<img usemap="#Map" src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/POL_location_map.svg/500px-POL_location_map.svg.png" alt="350 x 150 pic">
</map>
</body>
</html>
Let's not touch Selenium code not a teeny tiny bit.
Result? Selenium raises: selenium.common.exceptions.TimeoutException
And indeed, the Firefox window that shows up still shows the map of Poland, and not 'adsf'. If I click on this area in the Firefox window that shows up until the timeout of 100 seconds passes then Selenium immediately concludes the test has passed. But it was Selenium that was supposed to click on this element!!
What is happening and how to stop this madness?
Geckodriver 0.18.0. Selenium 3.5.0. Firefox 55.0.2. Python 3.5.2. And, if this matters, the dev server is Django 1.11.4.
The root cause is size of <area> on GeckoDriver is incorrect. Selenium WebDriver tries to click at the middle of the element but size of the area equals to the map. So Selenium clicks on a wrong position.
You can calculate the position and force Selenium to click at the position. See code below.
area = driver.find_element_by_id('clickhereyoustupidselenium')
coords = area.get_attribute("coords").split(',')
coordsNumbers = [ int(p) for p in coords ]
x = filter(lambda p: p % 2 != 0, coordsNumbers)
y = filter(lambda p: p % 2 == 0, coordsNumbers)
middleX = (max(x) - min(x))/2
middley = (max(y) - min(y))/2
action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element_with_offset(area, middleX, middley)
action.click()
action.perform()
WebDriverWait(driver, 100).until(EC.text_to_be_present_in_element((By.TAG_NAME, "body"), "adsf"))
print("Message found")
driver.quit()
TestNG.xml > only Executing First TestNG Test
I have copied the exact same working project, setup etc on a new device(PC) but when executing the same testng.xml it seems to execute only the first #Test across all test cases.
Running the test on my existing system works correctly.
For example #Test(priority = 1) only seems to be executing across all my 100+ TestNG Test classes.
Example Test File:
#Test(priority = 1)
public void LoadPage() throws Exception {
basePage.loadPage();
//Logs whether the Url and page Title is correct
DOMConfigurator.configure("log4j.xml");
Log.info("#PASS ---> Expected Site URL: " + basePage.page_url + " | Found the following Site URL: " + basePage.getPageUrl());
Log.info("#PASS ---> Expected Page Title: " + basePage.page_title + " | Found the following title: " + basePage.getPageTitle());
}
#Test(priority = 2)
public void hutLocaliseAndSelectOrderType() throws Exception {
phHomepage.enterHutPostcode();
hutLocalisePage.selectOrderType();
}
#Test(priority = 3)
public void SignIntoAccount() throws Exception {
basePage.pageJSLoadAndClick(pageHeader.button_SignIn);
//Sign into Account
signInPage.signIntoAccount();
//Validate whether Sign Out button is visible, once successfully signed into account
pageHeader.signOutButtonIsDisplayed();
}
**Listed in BasePage.java class**
public void loadPage() throws Exception{
driver.get(page_url);
Assert.assertEquals(driver.getCurrentUrl(), getPageUrl());
Assert.assertEquals(driver.getTitle(), getPageTitle());
}
<suite name="PH_Automation_Scripts_by_GBruno" verbose="2">
<test name="PH Automation Tests: Pizza Combinations" parallel="false">
<packages>
<package name="PhFramework.pizzas.*" />
</packages>
</test>
If i alter the above testng.xml to execute one test at a time the test executes fine.
#Phil_P85 - This is your testng xml file.
<suite name="PH_Automation_Scripts_by_GBruno" verbose="2">
<test name="PH Automation Tests: Pizza Combinations" parallel="false">
<packages>
<package name="PhFramework.pizzas.*" />
</packages>
</test>
Can you describe 'PhFramework.pizzas.*' ? If 'pizzas' is your package, can you try doing just '' see if it works.