Getting an error with 2.26 and 2.27 Selenium release while creating an Augmenter - selenium

When I create the Augmenter (see below) with 2.25 release of Selenium, it used to work fine. With 2.26 and 2.27 I'm getting the following error. Could you please suggest what extra is needed with a 2.26+ release to get things working again?
I get the following error:
java.lang.IllegalAccessException-->Class org.openqa.selenium.remote.Augmenter$CompoundHandler can not access a member of class org.openqa.selenium.firefox.FirefoxDriver with modifiers "protected"Exception caught starting Firefox webdriver
The relevant code:
WebDriver driver = new FirefoxDriver();
WebDriver augmentedDriver = new Augmenter().augment(driver);

Since newer release of selenium Agumenter only works for the RemoteWebDriver.
It was never really supported, but now is also doesn't work
Which feature you need the Agumenter for?
I.e. to take a screenshot you can make make a direct cast of the FriefoxDriver:
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
To initialize a mixed hub/local driver:
if (useHub) {
...
webDriver = new RemoteWebDriver(hubURL, desiredCapabilities);
webDriver = new Augmenter().augment(webDriver);
} else {
switch(webDriverType) {
case Type.FIREFOX:
webDriver = new FirefoxDriver();
}
}
then use webDriver as normal

Related

Selenium commands not working in Chrome web driver (working with firefox)

I'm writing integration/e2e tests and for some reason any selenium driver commands don't see to be working with chromedriver, but they are working flawlessly with firefox driver and the firefox headless driver.
Commands tried: moveByOffset, and doubleClick
Tried both Geb's Interact method
interact {
doubleClick(centerClickable)
}
and accessing the webdriver directly:
def driver = browser.getDriver()
Actions action = new Actions(driver)
WebElement element= driver.findElement(By.className("vis-drag-center"))
def doubleclick = action.doubleClick(element).build()
doubleclick.perform()
Both methods work with the firefox driver. Neither work with chrome driver.
GebConfig.groovy file is set up as thus:
import io.github.bonigarcia.wdm.WebDriverManager
import org.openqa.selenium.Dimension
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxOptions
def chromeWebDriverVersion = '70.0.3538.67'
def driverFirefox = {
WebDriverManager.firefoxdriver().setup()
def driver = new FirefoxDriver()
driver.manage().window().setSize(new Dimension(width, height))
return driver
}
// ChromeDriver reference: https://sites.google.com/a/chromium.org/chromedriver/
// Download and configure ChromeDriver using https://github.com/bonigarcia/webdrivermanager
def driverChrome = {
WebDriverManager.chromedriver().version(chromeWebDriverVersion).setup()
def driver = new ChromeDriver()
driver.manage().window().setSize(new Dimension(width, height))
return driver
}
environments {
firefox {
driver = driverFirefox
}
chrome {
driver = driverChrome
}
//driver = driverFirefox
driver = driverChrome
I also tried version 2.43 of chrome.
Additional information:
Mac Mojave
Selenium v 3.7.0
geb v 2.2
spockcore v 1.1-groovy-2.4
groovy v 2.4.5
webdrivermanager v 3.0.0
If anyone is interested, what the test is doing: Selecting a vis.js element by clicking on it. Sleeping for a second (code not included here), then opening/activating it by double clicking it. Or dragging it.
Apart from the selenium actions everything works fine with chromedriver and geb. It's only now that I need the doubleClick and moveByOffset (not move to an element!) that I'm getting issues getting things to work properly
I found a similar question on here, might be the same issue. Maybe not. But there's no solution provided: Selenium Web Driver DragAndDropToOffset in Chrome not working?
Any help is hugely appreciated.
Thank you for your response kriegaex.
Your tests work for me as well. This leads me to think there's just some lower-level interaction between differences in how selenium's chromedriver and firefox driver have implemented the doubleclick and dragAndDropBy actions + the way our application responds to commands.
For any other people observing similar behaviour, I use a work-around where I add an additional action for chromedriver. Perhaps it's nicer to actually find out which KEYDOWN events etc. you should be using and fire those, or perhaps find out why application isn't responding to these events. But I feel like enough time is spent on this already :)
if (browser.getDriver().toString().contains("chrome")) {
// Work-around for chromedriver's double-click implementation
content.click()
}
interact {
doubleClick(content)
}
And for the dragAndDropBy:
def drag(Navigator content, int xOff, int yOff) {
//Work-around: move additional time for when chrome driver is used.
int timesToMove = browser.getDriver().toString().contains("chrome") ? 2 : 1
interact {
clickAndHold(content)
timesToMove.times {
moveByOffset(xOff, yOff)
}
release()
}
}
I just had a little bit of time and was curious because I never tried to perform a double-click in any of my tests before. So I used this page as a test case and ran the following test with both Firefox and Chrome drivers:
package de.scrum_master.stackoverflow
import geb.spock.GebReportingSpec
import org.openqa.selenium.By
import org.openqa.selenium.interactions.Actions
class DoubleClickTest extends GebReportingSpec {
def "double-click via Geb interaction"() {
given:
go "https://demo.guru99.com/test/simple_context_menu.html"
def doubleClickButton = $("button", text: "Double-Click Me To See Alert")
expect:
withAlert {
interact {
doubleClick(doubleClickButton)
}
} == "You double clicked me.. Thank You.."
}
def "double-click via Selenium action"() {
given:
go "https://demo.guru99.com/test/simple_context_menu.html"
def doubleClickButton = driver.findElement(By.tagName("button"))
def doubleClick = new Actions(driver).doubleClick(doubleClickButton).build()
expect:
withAlert {
doubleClick.perform()
} == "You double clicked me.. Thank You.."
}
}
It works flawlessly, both ways of double-clicking trigger the expected Javascript alert.
I am not even using the latest driver version 2.45 but 2.41 against Chrome 71 64-bit on Windows 10. Besides, I also use bonigarcia's Webdriver Manager. I have no idea what is wrong with your setup. My Selenium version is 3.14.0, a bit newer than yours, Geb 2.2, Spock 1.1-groovy-2.4, Groovy 2.4.7.
Maybe it is a MacOS thing? I cannot verify that. Maybe you just run my test first, then maybe upgrade your Selenium and if that also does not help try to downgrade the Chrome driver in order to find out if the problem could be driver version related.
Update: I upgraded to Chrome driver 2.45, the test still works.
Update 2022-02-16: Updated the test to work with another example page, because the old URL still exists, but the Javascript there no longer works.

Appium can not operate the element

I'm using below code to test an Android App with Appium, but when I try to operate the element
driver.findElementById("com.TdMobile.ipems_app:id/login_ipaddress_edit").sendKeys("http://192.168.0.71:8080/ipems/");
I got java.lang.NullPointerException, when I debug into the line, I find the element is not null, does anyone know this happened?
AndroidDriver driver = null;
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("automationName", "Appium");//appium做自动化
cap.setCapability("app", "C:\\Users\\baiming.zhang\\Desktop\\IPEMS-APP.apk");
cap.setCapability("deviceName", "xiaomi-mi_5");//设备名称
cap.setCapability("platformName", "Android"); //安卓自动化还是IOS自动化
cap.setCapability("platformVersion", "6.0"); //安卓操作系统版本
cap.setCapability("udid", "794b155c"); //设备的udid (adb devices 查看到的)
cap.setCapability("unicodeKeyboard", "True"); //支持中文输入
cap.setCapability("resetKeyboard", "True"); //支持中文输入,必须两条都配置
cap.setCapability("noSign", "True"); //不重新签名apk
driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"),cap);//把以上配置传到appium服务端并连接手机
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);//隐式等待
driver.findElementById("com.TdMobile.ipems_app:id/login_ipaddress_edit").sendKeys("http://192.168.0.71:8080/ipems/");//this line failed.
driver.findElementById("com.TdMobile.ipems_app:id/login_user_edit").sendKeys("http://192.168.0.71:8080/ipems/");
driver.findElementById("com.TdMobile.ipems_app:id/login_passwd_edit").sendKeys("http://192.168.0.71:8080/ipems/");
driver.findElementById("com.TdMobile.ipems_app:id/login_login_btn").click();
The complete stacktrace is:
Exception in thread "main" java.lang.NullPointerException at
org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:275)
at
org.openqa.selenium.remote.RemoteWebElement.isDisplayed(RemoteWebElement.java:316)
at simple.CalculatorTest.main(CalculatorTest.java:47)
I changed AndroidDriver to RemoteWebDriver, than it works fine for me
A recent Selenium update to version 3.5.1 seems to have broken Appium's java client.
Further information here.
Although this thread refers Appium's java client 5.0.0-BETA9, I know that at least versions 4.1.x were also broken, because it happened to me.
So, the current workaround is to force selenium's version to 3.4.0, like so:
compile ('org.seleniumhq.selenium:selenium-api:3.4.0'){force = true}
compile ('org.seleniumhq.selenium:selenium-remote-driver:3.4.0'){force = true}
compile ('org.seleniumhq.selenium:selenium-support:3.4.0'){force = true}
It worked for me.

Geb: How to use Marionette instead of selenium Webdriver?

It is known issue that, Firefox version 47.0.1 is not compatible with Selenium latest version. Even Firefox is announcing to use Marionette instead. Can someone give some details instruction on how to use Marionette with Geb?
As a maven project, I tried all the version of Selenium with Geb but could not be successfull. I tried the following versions;
2.50.0
2.50.1
2.51.0
2.52.0
2.53.0
2.53.1
2.6.0
2.7.0
2.8.0
2.9.0
If this is not the right place to ask this, please guide me.
I have the next configuration in GebConfig.groovy:
firefox {
System.setProperty("webdriver.gecko.driver","path/geckodriver")
driver = {new MarionetteDriver()}
}
I am using selenium 3.0.1 and I using the -Dgeb.env=firefox system property in order to make sure it takes my Firefox configuration and it working fine for me
Regards
Download the latest version of selenium standard version 2.53.1 from selenium.hq.org.downloads and try to use the newest version of the Firefox.
With version 48 of Firefox, it looks like the only solution is using marionnette, however I have not been able to get this to work in Geb yet.
This is what I have tried in GebConfig.groovy:
environments {
firefox {
driver = {
DesiredCapabilities dc = DesiredCapabilities.firefox();
LoggingPreferences prefs = new LoggingPreferences();
prefs.enable(LogType.BROWSER, Level.WARNING);
dc.setCapability(CapabilityType.LOGGING_PREFS, prefs);
dc.setCapability("marionette", true);
String currentDir = System.getProperty("user.dir");
String marionetteDriverLocation = currentDir + "/WebDriver/wires";
System.setProperty("webdriver.gecko.driver", marionetteDriverLocation);
FirefoxProfile p = new FirefoxProfile();
p.setPreference("webdriver.gecko.driver", marionetteDriverLocation);
p.setPreference("webdriver.log.file", "/tmp/firefox_console");
p.setPreference("toolkit.telemetry.enabled", false);
p.setPreference("geo.enabled", false);
p.setPreference("plugins.update.notifyUser", false);
p.setPreference("datareporting.healthreport.service.enabled", false);
p.setPreference("datareporting.healthreport.uploadEnabled", false);
p.setPreference("datareporting.policy.dataSubmissionEnabled",false);
p.setPreference("datareporting.healthreport.service.firstRun", false);
p.setPreference("datareporting.healthreport.logging.consoleEnabled", false);
p.setPreference("reader.parse-on-load.enabled", false);
dc.setCapability(FirefoxDriver.PROFILE, p);
def driver = new FirefoxDriver(dc)
driver.manage().timeouts().pageLoadTimeout(45, TimeUnit.SECONDS)
return driver
}
It should work with any of the late Selenium versions. (everything > 2.50 not sure for earlier versions)
Marionette is an external driver, it's not included in the Selenium packages (yet?)
You need to Download the gecko driver here https://github.com/mozilla/geckodriver/releases
then point selenium to the location of the geckodriver.exe
You can do that as Nelson said before in GebConfig with:
import org.openqa.selenium.firefox.MarionetteDriver
driver = {
System.setProperty("webdriver.gecko.driver","path/geckodriver")
new MarionetteDriver()
}
to make that work you will need some dependencies in your buildscript, I'm working with gradle, yours might look different, just look into what yours need to look like on maven central
compile('info.novatec.testit:webtester-support-marionette:2.0.4') { transitive = false }
compile "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
compile "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
(selenium support might not be necessary for you)
If you need more help, a more specific description of where you are failing would be helpful, you can also look here for a working project (with maven):
http://seleniumsimplified.com/2016/04/how-to-use-the-firefox-marionette-driver/
public class Driver {
public FirefoxDriver getFirefoxDriver(){
System.setProperty("webdriver.gecko.driver", "./geckodriver.exe");
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
return new FirefoxDriver(options);
}
}

How to run selenium code

I have the code written for selenium, but I do not know how to make selenium read the code. I know that you have to put it in a certain folder somewhere though. I have never used this program or anything like it before. I just need to know how to make selenium read my code. I have no idea what I'm doing here.
public class GoogleTest {
WebDriver driver = new ChromeDriver();
String baseUrl = "google.com";;
Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
selenium.open("google.com");
selenium.type("name=q", "cheese");
selenium.click("name=btnG");
WebDriver driverInstance = ((WebDriverBackedSelenium) selenium).getUnderlyingWebDriver();
}
You need to write the following line before creating the driver object:
System.setProperty("webdriver.chrome.driver", "C:/path/to/chrome/driver/chrome.exe");
Try following code in same order:
System.setProperty("webdriver.chrome.driver", "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe");
WebDriver driver = new ChromeDriver();
String baseUrl = "google.com";;
Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
.
.
You may need to download the chrome driver as well.
link: https://code.google.com/p/selenium/wiki/ChromeDriver

WebDriver not opening URL

I'm very new to selenium so I'm having trouble spotting the problem with my code. I'm using a webDriver backed selenium object, it starts the driver but never opens the URL and the driver just closes after a few moments. The last time this happened to me it was just because I had left "http" out of the URL. So what's causing it this time?
public void testImages() throws Exception {
Selenium selenium = new WebDriverBackedSelenium(driver, "http://www.testsite.com/login");
System.out.println(selenium.getXpathCount("//img"));
}
The setup looks like:
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\User1\\Desktop\\chromedriver_win_16.0.902.0\\chromedriver.exe");
driver = new ChromeDriver();
Thread.sleep(2000);
}
The teardown method just consists of driver.close().
I'm using selenium 2.14 and the testNG Eclipse plug-in.
You might need to do the following
selenium.open("www.testsite.com/login");
Check out this example from the selenium site:
// You may use any WebDriver implementation. Firefox is used here as an example
WebDriver driver = new FirefoxDriver();
// A "base url", used by selenium to resolve relative URLs
String baseUrl = "http://www.google.com";
// Create the Selenium implementation
Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
// Perform actions with selenium
selenium.open("http://www.google.com");
selenium.type("name=q", "cheese");
selenium.click("name=btnG");
// Get the underlying WebDriver implementation back. This will refer to the
// same WebDriver instance as the "driver" variable above.
WebDriver driverInstance = ((WebDriverBackedSelenium) selenium).getUnderlyingWebDriver();
//Finally, close the browser. Call stop on the WebDriverBackedSelenium instance
//instead of calling driver.quit(). Otherwise, the JVM will continue running after
//the browser has been closed.
selenium.stop();
link to selenium
You would need to add driver.get(url) like below.
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\User1\\Desktop\\chromedriver_win_16.0.902.0\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://www.testsite.com/login");
}