Selenium Testing of GWT 2.0 - gwt

How can I make a selenium click() work the same as a manual mouse click?
I have recently upgraded GWT from 1.7.1 to 2.0. Some selenium tests (SeleniumRC v1.0.1, IE7) are now failing. It seems that the Selenium.click() method is not selecting a GWT TreeItem. A manual click will make the TreeItem go blue (ie. look selected and have "gwt-TreeItem-selected" class attribute in the DOM), but the selenium test doesn't.
I'm convinced that selenium is actually finding the right element, just not clicking on it. If you change the string parameter in the click method you can check that selenium throws an exception when the element isn't found.
The sample code below uses the GWT Showcase website. It tries to click on the word "Beethoven". If you click on that word with your mouse, you'll see the TreeItem go blue. However when you run the selenium test, it won't.
package test;
import org.junit.Before;
import org.junit.Test;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class TestTreeClick {
static Selenium selenium = null;
#Before
public void setUp() throws Exception {
if (selenium == null) {
selenium = new DefaultSelenium("localhost", 4444, "*iexplore",
"http://gwt.google.com/samples/Showcase/Showcase.html#CwTree");
selenium.start();
}
}
#Test
public void testingClicking() {
selenium.open("http://gwt.google.com/samples/Showcase/Showcase.html#CwTree");
selenium.click("gwt-debug-cwTree-staticTree-root-child0-content");
}
}
I have tried some other methods (Selenium.clickAt(), Selenium.fireEvent(), Selenium.mouseOver()/Down()/Up() ) - but none reproduce the manual behaviour.

Unfortunately having a look at this case I have not been able to replicate clicking with Selenium. I have seen a number of people complaining that they can't use Selenium with GWT and one of the more famous teams have that issue. The Google Wave development team have started using WebDriver to test their code.
Now the good thing is that there currently a project to merge Selenium and WebDriver as they have their strengths and weaknesses and a number of them are in different areas so the final product will be amazing.
I believe that they may have a working version of the WebDriverBackedSelenium at Google Code so all you would need to do is update the instantiation of Selenium and it should start using the WebDriver code to run your test.

It seems that WebDriver can do it like this.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Example {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new InternetExplorerDriver();
driver.get("http://gwt.google.com/samples/Showcase/Showcase.html#CwTree");
WebElement element = driver.findElement(By.id("gwt-debug-cwTree-staticTree-root-child0-content"));
element.click();
}
}
I'd still like to be able to do it with Selenium. It may be that a future Selenium release will more fully incorporate WebDriver, and everything will be wonderful again. But I guess this works for now.

I wanted to post the code that finally worked for me following useful comments from AutomatedTester.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.ie.InternetExplorerDriver;
import com.thoughtworks.selenium.Selenium;
public class TestTreeClick {
public static void main(String[] args) {
WebDriver driver = new InternetExplorerDriver();
Selenium selenium = new WebDriverBackedSelenium(driver, "http://gwt.google.com/samples/Showcase/Showcase.html#CwTree");
selenium.open("http://gwt.google.com/samples/Showcase/Showcase.html#CwTree");
selenium.click("gwt-debug-cwTree-staticTree-root-child0-content");
}
}

You don't actually need to "click" on that button, but press "Enter" on it instead.
See http://dingyichen.livejournal.com/23628.html

Related

Listener or rule for flutter_driver tests, to make automatically screenshot, if any one test failed

Hello!
There is huge trouble with taking automatically screenshot in flutter, if any test failed in test suite. In general I mean the same solution as it working in JUnit or TestNG.
Also I'm tried to wrap all test cases in try/catch, but it didn't work properly...
Please help if have any idea how to solve it.
Thanks in advance)
For example
In JUnit it's:
import com.codeborne.selenide.junit.ScreenShooter;
public class MyTest {
#rule
public ScreenShooter makeScreenshotOnFailure = ScreenShooter.failedTests();
// `enter code here`
}
In TestNG it's:
import com.codeborne.selenide.testng.ScreenShooter;
#listeners({ ScreenShooter.class})
public class MyTest {
// `enter code here`
}

Webdriver can login in Chrome, not in firefox: 'Unable to find owning document' error

I have 2 classes belonging to the same package in a java testNG project and I have declared 'webdriver driver' public static in class A. In that class, chrome launched, url opened, username and password were entered and login button clicked. Worked fine using #BeforeClass annotation.
I copied the same code into a class B and changed browser instance to firefox whilst still declaring 'webdriver driver as public static. Firefox Launched, URL opened, username and password were entered but login button did not click or submit. Test failed with the error:
org.openqa.selenium.JavascriptException: Error: Unable to find owning document.
I have never come across this error and have no idea what 'owning document' is being referred to.I am suspecting it has something to do with the access level for either or both classes. Below is an extract from the 2 classes. Am I missing something?
*
package com.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TheChrome {
public static WebDriver driver;
#BeforeClass(alwaysRun = true)
public void launchBrowser() {
driver = new ChromeDriver();
driver.get("http://www.example.com");
driver.manage().window().maximize();
#Test
public void verifyLogin() throws InterruptedException {
driver.findElement(By.id("username")).sendKeys("user");
driver.findElement(By.id("password")).sendKeys("password");
Thread.sleep(3000);
driver.findElement(By.id("loginButton")).click();
*
package com.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TheFirefox {
public static WebDriver driver;
#BeforeClass(alwaysRun = true)
public void launchBrowser() throws InterruptedException {
driver = new FirefoxDriver();
driver.get("http://www.example.com");
driver.manage().window().maximize();
Thread.sleep(3000);
}
#Test
public void verifyLogin() throws InterruptedException {
driver.findElement(By.id("username")).sendKeys("user");
driver.findElement(By.id("password")).sendKeys("password");
Thread.sleep(3000);
driver.findElement(By.id("loginButton")).click();
edit: See this very relevant question and answer
If you edit the post to include relevant html, this would be easier to help with.
Try with cssSelector:
Inspect the login button. Within the inspector, right click the element and copy the CSS Selector.
driver.findElement(By.cssSelector("copypasta")).click();
Try to locate by xpath using several different methods listed in this useful cheat sheet.
For example, if the inner html text for your button is 'Login':
driver.findElement(By.xpath("//button[contains(text(), 'Login']")).click();
There are many different ways to do this, so looking at your html will help people help you, I think.
This is an issue caused by the Firefox version in use, 49.0.2. It's a weird case and unclear why login functionality is being imparted by the browser version in use;however, resolving the issue requires a downgrade to version 46.0. This fixed the problem.

LDAP callback functionality

Masters,
I'm trying to implement LDAP callback functionality by referring to this article under "CALLBACKS"
I've configured LDAP without issue. My requirement is assign ldap user to CRX group depending on attribute in DS server. Now As per my understanding, when LDAP user will attempt login first time then CQ will automatically call my class which implements Callback interface. Please correct me if I am wrong.
So, I decided to create bundle which implements Callback interface. With my little knowledge I have done this so far -
i) In CRXDE lite, I added one bundle under geometrixx project and attached is the simple code but during building bundle I got error saying that Callback cannot be resolved to a type.
import org.apache.jackrabbit.api.security.user.User;
import org.apache.jackrabbit.api.security.user.Group;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.jcr.SimpleCredentials;
public class SyncUser implements com.day.crx.security.ldap.sync.Callback{
#Override
public void onUserSync(User userToBeSynched, Map<String, Value[]> attributes,
ValueFactory valueFactory) throws RepositoryException {
Iterator iter = attributes.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry mEntry = (Map.Entry) iter.next();
javax.jcr.Value val = (javax.jcr.Value)mEntry.getValue();
// Error** [Ljavax.jcr.Value; cannot be cast to javax.jcr.Value
System.out.println(mEntry.getKey() + " : " + val.getString());
}
}
#Override
public void onGroupSync(Group group,
Map<String, Value[]> attributes,
ValueFactory vf) throws RepositoryException{
System.out.println("Hello onGroupSync");//do my stuff
}
}
I could not find any documentation about this com.day.crx.security.ldap.sync.Callback interface. Kindly guide me. Appreciate your help
Here is at least some documentation for com.day.crx.security.ldap.sync.Callback: https://docs.adobe.com/docs/en/cq/5-6-1/core/administering/ldap_authentication.html#Callbacks
The doc you referenced says this:
The callback interface is located in the crx-auth-ldap module and has
the following methods that need to be implemented:
You need at least the following dependencies (jar files) to create and
build a callback class:
jcr-<version>.jar
crx-auth-<version>.jar
Both are bundled with the CRX Explorer Web Application and can be
extracted from the war file.
After you compiled and packaged the callback class you need to make it
available to CRX. The easiest way is to place the the custom callback
implementation along with the CRX webapp at
crx-quickstart/server/runtime/0/_crx/WEB-INF/[lib|classes].

Where do you find the JDBCProvider Interface?

As part of my ongoing JDBC/Oracle saga, I solicited the help of one of our Java/JDBC experts and after receiving some more input via my last question "For JDBC in XPages, how does the server know the connection information?" we imbarked on creating a plugin for my ojdbc14.jar file. We got the plugin created and tried to complile it. It complained that it could not find the JDBCProvider Interface. My question is where do I find this? Is this part of the Extension Library files on the Server or is this something completely different?
As always, any help will be greatly appreciated.
Thanks,
MJ
You'll want to pick com.ibm.commons.Extension in the Extension Point dialog, and then set the type as com.ibm.commons.jdbcprovider. Set the class to your JDBC driver provider class (named com.ZetaOne.JDBC.drivers.DB2.DB2DriverProvider for example) which i've provided sample code for below that looks like this (customized to your particular driver, etc)
package com.ZetaOne.JDBC.drivers.DB2;
import java.sql.Driver;
import java.sql.SQLException;
import com.ibm.commons.jdbc.drivers.IJDBCDriverAlias;
import com.ibm.commons.jdbc.drivers.JDBCProvider;
public class DB2DriverProvider implements JDBCProvider {
public DB2DriverProvider() {
{
public Driver loadDriver(String className) throws SQLException {
if(classNmae.equals(com.ibm.db2.jcc.DB2Driver.class.getName())) {
return new com.ibm.db2.jcc.DB2Driver();
}
return null;
}
}
Assuming you've done everything else needed for the plugin, you should be able to export / create your update site and install the driver.
BTW, you'll be able to read how to setup & deploy and use the JDBC package in ExtLibX in our upcoming book "XPages Extension Library: A Step by Step Guide to the Next Generation of XPage Controls" - available on amazon pre-order at http://www.amazon.com/XPages-Extension-Library-Step---Step/dp/0132901811
Hope this helps.

ZXing-1.7 Sample implementation issue

I recently started a small project in which I wanted to use zxing. I downloaded the sources from here. I was able to successfully build the core and the javase jars.
When I tried to code along the sample provided here I ran into a problem I do not quite understand. So far the code looks like this:
public static void main(String[] args)
{
Reader reader = new MultiFormatReader();
ImageIcon imageIcon = new ImageIcon(SOMEPATH);
Image image = imageIcon.getImage();
BufferedImage buffImage = new BufferedImage(
image.getWidth(null),
image.getHeight(null),
BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImage.createGraphics();
g.drawImage(image, null, null);
LuminanceSource source = new BufferedImageLuminanceSource(buffImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
}
As you can see this is pretty much the same code as presented in the DevelopersNotes. But the code will not compile. The error message is:
Type mismatch: cannot convert from BufferedImageLuminanceSource to LuminanceSource
Does somebody know what I am missing?
Edit:
My imports are currently looking like this:
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Reader;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
I added the core.jar as well as the javase.jar to my project. Both I compiled using ant leaving the buildfiles as downloaded.
That's all correct. You must have some funny business in your imports. Those types are certainly compatible.