Use information from view page source in automated test - java

Im trying to get some information from my page source. I run my automated tests on every release but want to avoid updating the release number manually as im trying to integrate my tests in CI and was hoping i could pull the tag from the page source.
All i know that works here is Drivers.getDriver.getPageSource but have no idea how to pull information.
The main issue im having is that the version is in 2 sections:
< meta http-equiv="version" content="1.4.39" >
I want to be able to take the 1.4.39 out of the page source and add to string

This surely is possible, you just had to have locator for this element.
For example if I take it's cssSelector as:
meta[http-equiv*='version']
We can easily do this:
driver.findElement(By.cssSelector("meta[http-equiv*='version']")).getAttribute("content")
This will return you 1.4.39 as String value.
Hope this helped.

Related

Buildfire: use buildfire.navigation.navigateTo (pluginData)

I'm trying to write a second menu to the home folder plugin and I want to write a piece of html in the text block (between the carrousel block and the Plugin Instances) so the user can navigate to another plugins.
How can I use the buildfire.navigation.navigateTo (pluginData) function there? How can I write the function using the ?
Where are the pluginData that the function needs?
- pluginId
- instanceId
- folderName
- title
Because when I'm trying to use it (I'm trying the navigateHome(); function to make sure it works), I get an Access Denied error.
Right now I'm trying this:
<a onclick="javascript:buildfire.navigation.navigateHome();">
and it doesn't work.
How can I navigate to another plugins?
Thanks in advance.
Here is the official documentation on Navigation https://github.com/BuildFire/sdk/wiki/How-to-use-Navigation
Fundamentally javascript:buildfire.navigation.navigateHome() should work. Please post the error you receive so we may review it.
Navigating to another plugin can be done with
buildfire.navigation.navigateTo (pluginData)
pluginData {
pluginId: (string) The id of the plugin type you'd like to navigate to.
,instanceId: (string) The the instance of the plugin you'd like to navigate to.
,folderName (string) The folder name of the plugin that you'd like to navigate to.
,title (string) The title that should show up in the title bar once the plugin is loaded.
,queryString (string) Optional. This is a query string that will be passed to the next plugin's window.location.search. example: "name=Larry&age=36&showDetails=true"
}
Ref: https://github.com/BuildFire/sdk/wiki/How-to-use-Navigation#buildfirenavigationnavigateto-plugindata
You also should take a look at Dynamic Data to make sure you have the latest references to the plugin as they may change
Ref: https://github.com/BuildFire/sdk/wiki/How-to-use-the-Datastore-Dynamic-Data
All this being said, I'd like to draw your attention to ActionItems which are currently implemented in your carousel
Ref: https://github.com/BuildFire/sdk/wiki/BuildFire-Action-Items-Component

How to use SchemaCrawler's Offline Snapshots in Java code

I think the header explains it all: Is there a nice way to create and load offline snapshots of database schema using SchemaCrawler without using command line? If yes, can you provide some example code / link please? If not, some example java code to use command line options would be helpful too (I don't have much experience with that)!
Thanks for any kind of help!
PS: I managed to create offline snapshot with this code:
final SchemaCrawlerOptions options = new SchemaCrawlerOptions();
// Set what details are required in the schema - this affects the
// time taken to crawl the schema
options.setSchemaInfoLevel(SchemaInfoLevelBuilder.standard());
options.setRoutineInclusionRule(new ExcludeAll());
options.setSchemaInclusionRule(new RegularExpressionInclusionRule(/* some regex here*/));
options.setTableInclusionRule(new RegularExpressionExclusionRule(/*some regex here*/));
outputOptions.setCompressedOutputFile(Paths.get("./test_db_snapshot.xml"));
final String command = "serialize";
final Executable executable = new SchemaCrawlerExecutable(command);
executable.setSchemaCrawlerOptions(options);
executable.setOutputOptions(outputOptions);
executable.execute(getConnection());
Not sure how to connect to it though.
You need to use the schemacrawler.tools.offline.OfflineSnapshotExecutable along with an schemacrawler.tools.offline.jdbc.OfflineConnection to "connect" to your database snapshoot.
Please take a look at the following code:
OfflineSnapshotTest.offlineSnapshotExecutable()
And #ZidaneT, to load an offline snapshot, use code like that in LoadSnapshotTest.java
Sualeh Fatehi, SchemaCrawler

Can't use Row Data Resulted from Scripted DataSet

Performing a test with BIRT I was able to create a report and render it in PDF, but unfortunatelly I'm not getting the expected result.
For my DataSource I created a Scripted DataSource and no code was needed in there (as far as I could see the documentation to achieve what I'm trying to do).
For my DataSet I create a Scripted DataSet using my Scripted DataSource as source. In there I defined the script for open like:
importPackage(Packages.org.springframework.context);
importPackage(Packages.org.springframework.web.context.support);
var sc = reportContext.getHttpServletRequest().getSession().getServletContext();
var spring = WebApplicationContextUtils.getWebApplicationContext(sc);
myPojo = spring.getBean("myDao").findById(params["pojoId"]);
And script for fetch like:
if(myPojo != null){
row["title"] = myPojo.getTitle();
myPojo = null;
return true;
}
return false;
As the population of row will be done on runtime, I wasn't able to automatically get the DataSet columns, so I created one with the following configuration: name: columnTitle (as this is the name used to populated row object in fetch code).
Afterwards I edited the layout of my report and added the column to my layout.
I was able to confirm that spring.getBean("myDao").findById(params["pojoId"]); is executed. But my rendered report is not showing the title. If I double click on my column label on report layout I can see there that expression is dataSetRow["columnTitle"] is it right? Even I'm using row in my fetch script? What am I missing here?
Well, what is conctractVersion?
It is obviously not initialized in the open event.
Should this read myPojo.contractVersion or perhaps myPojo.getContractVersion()?
Another point: Is the DS with the column "columnTitle" bound to the layout?
You should also run your report as HTML or in the previewer to check for script errors.
Unfortunately, these are silently ignored when generating the report as PDF...
The problem was the use of batik twice (two different versions), one dependency for BIRT and other for DOCX4J.
The issue is quite difficult to identify because there is no log output rendering PDF files.
Rendering HTML I could see an error message which I could investigate and find the problem.
For my case I could remove the DocX4j from maven POM.

:first / :first-child doesn't seem to work with Selenium 2

While migrating from Selenium 1 to Selenium 2 I am running into a problem.
I have the structural equivalent of the following:
<ul id="documentType">
<li>first</li>
<li>second</li>
<li>third</li>
</ul>
Previously I would in Selenium 1 use the following css selector to find the first anchor link:
#documentType li:first-child a
This would work great, however, when I switch to selenium 2 and try and use the equivalent I get element not found. The following does work but is less precise then I would like.
#documentType li a
I have tried but could not get to work the following:
#documentType li:first a
For greater detail I'm using HtmlUnitDriver with the following code:
driver.findElementByCssSelector("#documentType li a");
Any help on getting the equivalent of the original selector working I would greatly appreciate it!
I be confused :)
EDIT: Phill Sacre brought up a good point on the fact I'm directly using HtmlUnitDriver which could be the source of the problem since it's a pure java implementation. I do this specifically for the ability to deal with a nasty Ajax problem of how to know when Ajax is done running. You can do this with the following code:
protected void waitForAjaxToComplete() {
long result = jQueryActive();
while (result != 0) {
result = (Long) driver.executeScript("return jQuery.active;");
}
}
This is obviously advantageous over using the technique of waiting for an element to appear which can be very inaccurate. I wish WebDriver would expose the executeScript method which would resolve this problem.
Further I noted that by default HtmlUnitDriver does use a java based implementation to parse the css selector supplied and I'm guessing this is the source of the problem. The parser is com.steadystate.css.parser.SACParserCSS21.SACParserCSS21 which may not properly take into account the :first and :first-child qualifiers.
What seems to make this ok is that the behavior of HtmlUnitDriver seems to return the first element by default. It's sister method findElementsByCssSelector seems to return an ordered list.
As a result while this appears to be a bug I may have answered my own question by learning how HtmlUnitDriver operates.
Which browser were you doing your Selenium 1 testing on? Looking in the Selenium documentation, the HtmlUnit driver is a pure-Java solution (i.e. it doesn't run in a browser, obviously).
Now I think there are some differences in selectors between browsers, so if you were using the Firefox browser before it may be worth using the FirefoxDriver to run your Selenium 2 tests?
Similar to Phill's answer- HtmlUnit parser the page differently than FF. I would start the debugging process by running the same test using the FF driver and see if it passes there. If it does pass, then the next step I would do is get the HTML from the HtmlUnit driver (I guess the command would be driver.getPageHtml() or something similar). I would compare that html with the html you get when you look at the html through a real browser (FF, chrome,..). Sometimes you see that tags have been put in by the real browser (i.e., by its parser) or by the HtmlUnit browser. You can either correct your selector or use a different driver (or go tell the developers to fix their html because that what usually causes these problems :-)
I had the same problem with this selector (using Spock/Geb). This has been resolved in the new version of Geb which is 0.9.2 (which has the changes to the HTML unit driver too). Now $('tr:first-child a') works fine with HTMLUnitDriver
I can provide the following CSS Selectors
1. css=#documentType > li > a -- First Link
2. css=#documentType > li+li > a -- Second Link
3. css=#documentType > li+li+li > a -- Third Link
else, you can try
1.css=#documentType > li:nth-child(2) > a -- Second Link
2.css=#documentType > li:nth-child(3) > a -- Third Link

How do I overwrite the URL in an IE address bar using RFT?

I need to execute the following steps:
1. Start an IE browser window and open a URL (Done using StartBrowser(final string URL)
2. Start a session (done by logging in)
3. Now, I want to enter a different URL in the same browser window which has the same session.
My question is related to Step 3. How can I overwrite the URL in the existing IE window.
Note: I am using a keyword driven framework written in java.
From the IBM RFT online help: You can use the loadURL() method of the browser object.
If you do not have the browser object already 'learned' into your object map, just record a click on the browser toolbar. Then you can modify that line to be Browser_htmlBrowser().loadURL("http://stackoverflow.com");
Thanks Tom. I agree that loadURL has the implementation to do what I need.
There is one more aspect that may interest others looking at this question, i.e. the way the appropriate browser object is captured. Obviously the easist way is to use the RFT record and click way, and use the appropriate recognition properties or the other way is to implement it is find the existing browseron the fly when the method is called irrespective of recognistion properties etc which may be more useful for some scenarios or frameworks, like it is done below.
RootTestObject root = getRootTestObject();
TestObject[] testobj = root.find(atDescendant(".class", "Html.HtmlBrowser"));
BrowserTestObject bto;
bto = new BrowserTestObject(testobj[0]);
bto.loadUrl(curParamOne);

Categories

Resources