Unable to find browser object in RFT 8.5 - rft

I installed RFT 8.5 and JRE 7. When I run the scripts it's not finding browser object.
Below is the code which I have used in RFt to find the brwoser object.
Dim Allobjects() as TestObeject
Allobjects=RootTestObject.GetRootTestObject.Find(".class","Html.HtmlBrowser"))
Here it's is returning Allbects.lenth=0. Because of the I am getting struck.
Anybody can help me how to resolve this issue.
Note: I am using IE8

I was not able to find the browsers using RootTestObject either. But it is possible to find the browser windows using the Html domains:
startApp("Google");
startApp("asdf");
sleep(5);
DomainTestObject[] dtos = getDomains();
List<DomainTestObject> htmlDomains = new ArrayList<DomainTestObject>();
for (DomainTestObject dto : dtos) {
if (dto.getName().equals("Html")) {
htmlDomains.add(dto);
}
}
List<BrowserTestObject> browsers = new ArrayList<BrowserTestObject>();
for (DomainTestObject htmlDomain : htmlDomains) {
TestObject[] tos = htmlDomain.getTopObjects();
for (TestObject to : tos) {
if (to.getProperty(".class").equals("Html.HtmlBrowser")) {
browsers.add((BrowserTestObject) to);
}
}
}
System.out.println("Found " + browsers.size() + " browsers:");
for (BrowserTestObject browser : browsers) {
System.out.println(browser.getProperty(".documentName"));
}
Output:
Found 2 browsers:
https://www.google.ch/
http://www.asdf.com/
First, I start 2 browsers. Then I get all Html domain test objects. After that, I get all top objects and check whether their class is Html.HtmlBrowser.
I hope there is a simpler solution—looking forward to seeing one :)

Try the below code Snippet:
Dim Allobjects() As TestObject
Allobjects = Find(AtDescendant(".class", "Html.HtmlBrowser"))
Hope it helps.

Browser is a toplevel window so what you can do is :
Dim Allobjects() as TestObeject
Allobjects=Find(AtChild(".class","Html.HtmlBrowser"))
'The above code expects the browser to be statically enabled , also RootTestObject is not needed as implicitly RFT will use the RootTestObject if no anchor is provided.
Also if the browser is not statically enabled then you could also use:
DynamicEnabler.HookBrowsers() API so that browsers get enabled.

Related

How to run Selenium test using Edge headless

Some time ago, I wrote some Selenium unit tests and these used the Firefox browser (headless). After a few years, I have returned to these (and cannot now remember how they worked) and would like to update them to use the Edge browser (in headless mode). How do I do this ? Specifically, when I ask the IWebDriver to "Navigate", how does it know the root URL - specifically the port ? I presume that my URL would be "http://localhost:nnnn/blah...", but how do I determine the port (which I also presume I need) ?
My code is based upon the following:
protected IWebDriver GetBrowserEdge(bool headless = true)
{
var service = SeleniumTools.EdgeDriverService.CreateChromiumService();
service.UseVerboseLogging = true;
var options = new SeleniumTools.EdgeOptions { PageLoadStrategy = PageLoadStrategy.Normal, UseChromium = true };
if (headless) options.AddArgument("headless");
return new SeleniumTools.EdgeDriver(service, options);
}
I wasn't using "CreateChromiumService" before (and I note it is disposable - which gives me a design issue), but I note that the service it returns has a "port" property. Do I need to leverage that in my "IWebDriver.Navigate" calls ?
I am using Edge v92.0.902.73 and Microsoft.Edge.SeleniumTools v3.141.2

Is it possible to ignore Firefox for running the feature?

I am trying to use tags for ignoring Firefox for running few feature files.
I mean something like:
#Browser_Chrome
Feature: My Functionality
#ignore #Browser_Firefox
Scenario:
Given blablabla"
Is it possible?
Now looks like #ignore tag is working in any way
You can always check within your tests using getCapabilities(https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/remote/RemoteWebDriver.html#getCapabilities--):
assumeTrue( !(driver as RemoteWebDriver).capabilities
.getCapability("browserName").equals("firefox") ) )
More info about assume: https://junit.org/junit4/javadoc/4.12/org/junit/Assume.html
If you want to run almost all tests on Firefox, but want to exclude some. I would use a tag with a matching beforescenario which does the ignoring.
Feature file:
#BeforeExcludeFF #ThisIsMyFeature
Scenario: Dont run this when the browser is Firefox
Given blablabla
When blablabla
Then blablabla
Code behind:
[BeforeScenario("BeforeExcludeFF", Order = 1)]
public void BeforeExcludeFF()
{
// we need to get the current browser to know if it is firefox
ICapabilities capabilities = ((RemoteWebDriver)driver).Capabilities;
string browser = capabilities.GetCapability("browserName");
if(browser.ToLower() == "firefox")
{
// don't forget to log WHY we ignore this scenario on FF
LogToConsoleAndIgnore(#"We dont want to run this scenario because ");
}
}
private void LogToConsoleAndIgnore(string reason)
{
Console.WriteLine(reason);
Assert.Ignore(reason);
}
Hope this helps.

Spring shell 2.0 how to read inputs with mask

Is there any way to mask user inputs in Spring Shell 2.0.x ?
I need to collect password from user.. did not find any shell api to do that.
Thanks!!
Found that LineReader#readLine(msg,mask) provides that option.
All you have to do is inject the LineReader bean.
If you don't want to rely on third party libraries, you can always do a standard Java console input, something like:
private String inputPassword() {
Console console = System.console();
return new String(console.readPassword());
}
Note though that when running this in an IDE, the System.console() might be null. So you should probably handle that if running in an IDE is something you want to support (for testing for example..) something like:
private String inputPassword() {
Console console = System.console();
// Console can be null when running in an IDE
if (console == null) {
System.out.println("WARNING - CAN'T HIDE PASSWORD");
return new Scanner(System.in).next();
}
return new String(console.readPassword());
}

Alfresco + Selenium WebDriver. Wait for AJAX

I'm developing tests with TestNG and Selenium WebDriver for some custom Alfresco modules being developed by our team.
After the page loading I need to wait for all AJAX requests to get necessary WebElement.
I found this approach. I've figured out that Alfresco uses Dojo.
So i wrote a following method (timeout is yet to be added):
void waitForAJAX() {
if(javascriptExecutor == null) {
throw new UnsupportedOperationException(webDriverType.toString() + " does not support javascript execution.");
}
boolean presentActiveConnections = true;
Integer numOfCon;
// Minor optimization. Getting rid of the repeaedly invocation of valueOf() in while.
Integer zeroInteger = Integer.valueOf(0);
while(presentActiveConnections) {
numOfCon = (Integer)javascriptExecutor.executeScript("return selenium.browserbot.getCurrentWindow().dojo.io.XMLHTTPTransport.inFlight.length");
if( numOfCon.equals(zeroInteger) ) {
presentActiveConnections = false;
}
}
}
But when i run my tests i get following error on invocation of this method from the test:
Failed: ReferenceError: dojo is not defined.
Should dojo variable be available from any javascript? I was unable to locate it too when i manually checked the page source.
Thanks in advance.

Start Default Browser - Windows

When starting the default browser like this:
Dim trgt1 As String = "http://www.vbforums.com/showthread.php?t=612471"
pi.FileName = trgt1
System.Diagnostics.Process.Start(pi)
It takes about 40 seconds to open the page.
If I do it like this, though this isn't the default browser
Dim trgt1 As String = "http://www.vbforums.com/showthread.php?t=612471"
pi.Arguments = trgt1
pi.FileName = "iexplore.exe" 'or firefox.exe
System.Diagnostics.Process.Start(pi)
it opens immediately. Is this a bug or a feature? I have tried this with both IE and FireFox set to be the default browser.
1
Windows is running through the registry looking for an appropriate application to open the document with (via explorer.exe).
2
You are explicitly telling windows to use xxx.exe to open the document.
Update for the moving target: ;-)
The reason it is so slow is that the Url you are specifying doesn't look like anything it knows how to open, with a browser or otherwise, and has to employ brute force in determining this.
If you wan to speed up launching with the default browser, get it from HKEY_CURRENT_USER\Software\Classes\http\shell\open\command and use #2.
Use this function to retrieve path of default browser
/// <summary>
/// Reads path of default browser from registry
/// </summary>
/// <returns></returns>
private static string GetDefaultBrowserPath()
{
string key = #"htmlfile\shell\open\command";
RegistryKey registryKey =
Registry.ClassesRoot.OpenSubKey(key, false);
// get default browser path
return ((string) registryKey.GetValue(null, null)).Split('"')[1];
}
Opens URL in default browser from within the C# program.
string defaultBrowserPath = GetDefaultBrowserPath();
try
{
// launch default browser
Process.Start(defaultBrowserPath, "http://www.yahoo.com");
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
Opens URL in separate instance of default browser from within the C# program.
// open URL in separate instance of default browser
Process p = new Process();
p.StartInfo.FileName = GetDefaultBrowserPath();
p.StartInfo.Arguments = "http://www.yahoo.com";
p.Start();
From this blog post
I respectfully differ with the Sky. I have tried this on numerous machines now and the value
string key = #"htmlfile\shell\open\command";
seems to always default to IE even if Chrome is set to the default browser. Now, to be honest I have not tried this on machines with firefox set to the default browser only chrome, so it could do with more testing but the value does seem to only store IE from my testing.
Hope this helps those who use alternative browsers.
I am going to stick with process.start(url) as that pretty much guarantees that you get the users default browser every time. Let the framework handle it! that is why MS built it...