Ambiguous method call in appium WebDriver findElement API - selenium-webdriver

I am using appium 6.1.0 which has <T extends WebElement> T findElement(By by); method on WebDriver class. Somewhere in automated tests I have following APIs -
protected String getText(WebElement element) {
return getText(element, Config.LOAD_WAIT);
}
and
protected String getText(By by) {
return getText(by, Config.LOAD_WAIT);
}
And getText method is invoked by test as -
public String getFullName() {
return getText(driver.findElement(By.cssSelector(".basicDataSection)))
}
But using WebDriver class from appium dependency throws exception on getFullName method about method call being ambiguous since it matches both getText(WebElement element) and getText(By by) How is this possible since findElement return type is T extends WebElement in WebDriver class in appium dependency?
On a different note, there is also WebElement findElement(By by); API in WebDriver class in selenium-api but after adding appium dependency method in my project they have begun to refer to WebDriver class from appium dependency and not from selenium-api dependency. Unfortunately WebDriver api in both classes have same package org.openqa.selenium.
I am not sure if WebDriver class from appium and selenium-api can be used interchangeably as they have different automation purpose (i.e. mobile app and web app). If WebDriver class from appium and selenium-api can not be used interchangeably then is there a way to enforce to use WebDriver class from selenium-api dependency and not from appium dependency?

Consider using MobileElement instead of WebElement to avoid clashes with underlying Selenium API
Make sure to have only appium-java-client library in your project dependencies, Appium 6.1.0 assumes Selenium 3.12.0 so you have to use exactly this version of Selenium in order to avoid Jar Hell so I would recommend using dependency management solution like Maven or Gradle to automatically resolve Appium Java client library and all its transitive dependencies. See Code Examples -> Appium with Java for comprehensive information and sample projects

Related

Using non Static Java Class in Mule

I'm trying to implement some custom Java code in a non-static manor. I've used the "NEW" component under Java modules, so I can use the "INVOKE" component later.
XML for Component
<java:new doc:name="New" doc:id="b45f35b5-d524-45df-b006-a962d0a8ce69" class="com.company.LockComponent" constructor="LockComponent()"/>
I then added a classLoaderModelLoaderDescriptor to my mule-artifact.json, as shown below.
{
"minMuleVersion": "4.1.5",
"classLoaderModelLoaderDescriptor": {
"id": "mule",
"attributes": {
"exportedPackages":[
"com.company.LockComponent"
]
}
}
}
I'm getting JAVA:CLASS_NOT_FOUND error. I'm not sure what I'm missing...
Ensure that:
The applications uses the latest Java Module version.
The application uses the latest Mule Maven Plugin version.
The Java source for the class is included with your project (src/main/java) or as a dependency in Maven.
You should not need to modify mule-artifact.json with above steps.

Gecko driver issue

am unable to open browser using geckodriver 3.8.1 and selenium oxygen and firefox 57.0.4(32 bit) version
package Selenium_JavaFundamentals;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class opengmail {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com");
}
}
I am getting following error:
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases
at com.google.common.base.Preconditions.checkState(Preconditions.java:754)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:141)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:158)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:98)
at Selenium_JavaFundamentals.opengmail.main(opengmail.java:10)
Please note that I have loaded the gecko driver.
You need to explicitly tell it where the WebDriver is.
Like this:
package Selenium_JavaFundamentals;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class opengmail {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
System.setProperty("webdriver.gecko.driver", "/path/to/geckoDriver.exe");"
driver.get("https://www.google.com");
}
}
From some research, I came across that
WebDriver uses native browser approach. Selenium offers inbuilt driver
for Firefox but not for other browsers. All drivers (Chrome Driver, IE
driver, etc.) are built based on the special JS Engine used by each
browser.
So I suppose
System.setProperty("webdriver.gecko.driver","/path/to/geckoDriver.exe");"
isn't required for Firefox after all.
What seems to be the issue here is broken Firefox installation in your machine. Scrub your current installation completely and do a fresh install of the compatible Firefox. (Optional- Also you can put the Firefox.exe path in your PATH in Environment Variables.)
For this issue, i simply downgraded my firefox browser version- 43 this issue got resolved after downgrading the browser
Set the geckodriver.exe location first before initializing the FirefoxDriver.
For selenium 3.x with Firefox
System.setProperty("webdriver.gecko.driver", "path.to.geckodriver.exe");
WebDriver driver = new FirefoxDriver();

The constructor FirefoxDriver(FirefoxOptions) is undefined

I am using Selenium 3.5.3 and following is my code.
I am trying to use Firefox options in the constructor as in
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/firefox/FirefoxDriver.html#FirefoxDriver-org.openqa.selenium.firefox.FirefoxOptions-
FirefoxOptions options=new FirefoxOptions();
options.setProfile(profile);
driver =new FirefoxDriver(options);
I am getting an error in instantiating the Firefox driver:
The constructor FirefoxDriver(FirefoxOptions) is undefined
How can I solve this?
Firefox version 55.0.3 64 bit
Geckodriver v0.18.0
Try this code:
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
public class FirefoxOptionsDemo {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "E:\\software and tools\\geckodriver.exe");
FirefoxProfile profile =new FirefoxProfile(new File("C:\\Users\\sys\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\ejtrne37.QAProfile"));
FirefoxOptions option=new FirefoxOptions();
option.setProfile(profile);
// Initialize Firefox driver
WebDriver driver = new FirefoxDriver(option);
//Maximize browser window
driver.manage().window().maximize();
//Go to URL which you want to navigate
driver.get("http://www.google.com");
//Set timeout for 5 seconds so that the page may load properly within that time
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//close firefox browser
driver.close();
}
}
This is the image for your reference:
The issue is due to older selenium version coexisted. mvn clean install resolved the issue.
Your problem may be related to different causes.
The common cause is a misaligned version of your firefox browser and/or gecko driver and/or selenium library.
I solved this problem upgrading gecko driver and selenium library to the latest version.
In my case, mvn clean install does not resolved the problem
Since an upgrade to current available release versions is not a doable action by many since it is not acceptable to their teams due to the impact - so they need a working fix for current in use version itself hence my answer -
I may be answering it a lot late but my solution is a workable one for this problem and I can even explain why it is workable and why above one is not workable as asked in your query -
For older selenium and gecko driver versions, the above suggested method i.e. Options class utilization used to work from Selenium 3.5 and upwards (officially) but for versions lower than 3.5 - the options class was not available, so the above suggested method does not work.
I backtracked and found that even in the most widespread popular Selenium version 3.14(which I ended up using for project specific needs, even though the current stable release is at Selenium 4.5 :D) the options class and above suggested method does not work.
So the alternative is just to replace the import of options class and utilization of any of its methods.
In my code I just used direct paths for geckodriver and firefox exe paths and then instantiated the FirefoxDriver class object via WebDriver interface and the constructor is undefined error stops troubling as it is we are not passing any argument in constructor as expected by Eclipse JVM:
Here are my exact lines of code to solve this -
System.setProperty("webdriver.gecko.driver", "D:\\Selenium Projects\\BrowserDrivers\\geckodriver.exe");
System.setProperty("webdriver.firefox.bin", "C:\\Program Files\\Mozilla Firefox\\firefox.exe" );
driver = new FirefoxDriver();
Rest of the code remains as is originally.
The above method of options class utilization or multiple arguments in constructor are supported only after Selenium 3.6. If you use latest selenium and geckodriver, then I dont think you will run in above problem at all as I was able to see it working in the latest versions.
But sometimes we can't just upgrade to our wishes, and we need a fix in the current used versions itself, hence this solution has been suggested by me.

How do I set up Allure with JUnit in an IntelliJ project?

I've been reading in the Allure wiki however I do not seem to be able to get started with Allure.
I have an IntelliJ project which I use to run JUnit tests with Selenium. I want to add Allure for better feedback after test runs. However I've not been able to understand how Allure would integrate with the rest of my project.
On the wiki page for JUnit it looks like Allure with JUnit only supports maven projects? How can I set up allure to work with an IntelliJ project?
I want to add Allure for better feedback after test runs
It is strange that you don't have a build tool.
But for single test (as you mention) following will work.
Dependencies - you need aither allure-junit-adaptor or allure-testng-adaptor
Allure implements test listener, which should be added to test runner:
For TestNG it happens automatically (once you add adaptor dependency).
For JUnit you should add listener manually. I don't know how to add it to Intellij Idea JUnit runner, but you can always run tests programmatically:
public static void main(String[] args) {
JUnitCore runner = new JUnitCore();
runner.addListener(new AllureRunListener());
runner.run(CalculatorTest.class);
}
That will generate XML report in target/allure-results folder.
If you need advanced Allure features like file attachments and test steps you need another dependency (aspectjweaver) and according JVM args, e.g.
-javaagent:lib/aspectjweaver-1.8.7.jar
To generate HTML report from existing XML report you can:
either use Allure CLI (requires tool installation http://wiki.qatools.ru/display/AL/Allure+Commandline)
or use 'mvn site' on existing project (e.g. https://github.com/allure-examples/allure-junit-example)
Open your HTML report in Firefox (or look here how to open locally generated report in Chrome).
To have allure-results after launching JUnit4 tests from IDE using context menu or controls on the gutter I use #RunWith anntotation where I set my custom runner with AllureJUnit4 listener.
CustomRunner class
package ru.atconsulting.qa.system.junit4runners;
import io.qameta.allure.junit4.AllureJunit4;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;
public class CustomRunner extends BlockJUnit4ClassRunner {
/**
* Creates a BlockJUnit4ClassRunner to run {#code klass}
*
* #param klass
* #throws InitializationError if the test class is malformed.
*/
public CustomRunner(Class<?> klass) throws InitializationError {
super(klass);
}
#Override
public void run(RunNotifier notifier) {
notifier.addListener(new AllureJunit4()); //just add listener
super.run(notifier);
}
}
Using #RunWith annotation in test classes
#RunWith(CustomRunner.class)
public class ExampleSuite {
#Test
public void testExample() {
....
}
}

FUBAR after update to GAE-java-sdk-1.6.0/1.6.1 persistencemanager singleton

After I updated from GAE-JAVA-SDK-1.5.5 to 1.6.0 and 1.6.1 my app stop functioning properly. it started giving an error on the RPC service.
Exception while dispatching incoming RPC call com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract void com.skip.school.client.service.AdminService.addStudent(com.skip.school.shared.Student)' threw an unexpected exception: java.lang.NoClassDefFoundError: Could not initialize class com.skip.school.server.PmfSingleton
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.skip.school.server.PmfSingleton
The whole log can be found here pastebin.
I have a singleton that should be initialized when the user starts there first rpc call.
The singleton I use should be correct there are many example found here on stackeroverflow and everywhere on the web.
public final class PmfSingleton {
private final static PersistenceManagerFactory pmfInstance = JDOHelper.getPersistenceManagerFactory("transactions-optional");
private PmfSingleton() { }
public static PersistenceManagerFactory get() {
return pmfInstance;
}
}
I call that class in all my server implementations like so.
PersistenceManager pm = PmfSingleton.get().getPersistenceManager();
this works on sdk 1.5.5 and below but not on sdk 1.6.0 and above, does anyone know what I' doing wrong what i should change if i want to use sdk 1.6.0 and above?
I read somewhere else that this problem is related to an out dated version of the datanucelus jars. I've updated to the latest version, v1.6.1 available from the eclipse plugin and I fixed it by deleting all old references to the old jars, leaving behind just these 3:
datanucleus-appengine-1.0.10.final.jar
datanucleus-core-1.1.5.jar
datanucleus-jpa-1.1.5.jar
I hope that works for you!
I had this same problem after upgrading to a newer version of AppEngine SDK. It turns out the problem was I had an older version of the appengine-api-1.0-sdk jar hanging around in the deployment folder.
Have a look in the war\WEB-INF\lib folder of your application and see if there are two different versions of appengine-api-1.0-sdk-1.x.y.jar. I fixed it by removing the appengine-api-1.0-sdk-1.5.x file.

Resources