I need to debug selenium/appium tests in eclipse that are written in Java. The script is running through eclipse and I can see it in the device but I hit some error so I wanted to debug. In eclipse I opened the debug perspective and setup break points in the script. Then I am running the test from Run --> Debug As --> TestNG Test , keeping everything else same.
But the code is not stopping at breakpoints. It is behaving like running the script normally (without debug). How do run so the code stop at breakpoints and then we step into?
Not sure if this is of help,but, This is how I am initiating the driver
public AndroidDriver InitiateDriver() throws MalformedURLException {
nodeURL= "http://localhost:4723/wd/hub" ;
DesiredCapabilities capability = DesiredCapabilities.android();
capability.setCapability("BROWSER_NAME", "Android");
capability.setCapability("VERSION", "7.0");
capability.setCapability("platformName", "Android");
capability.setCapability("appPackage", "com.accuweather.android");
capability.setCapability("appActivity", "com.accuweather.app.SplashScreen");
capability.setCapability("deviceName", "ec8d4453");
AppDriver = new AndroidDriver(new URL(nodeURL), capability);
return AppDriver;
}
In the eclipse menu bar Go to Run menu and please make sure that "Skip All Breakpoints" option is not selected(if it is selected already then unselect that option).
In trying to search for an answer to my question , I came across Appium Java REPL , which can be used for real time debugging of appium java tests.
Though its not with eclipse, but it solve the purpose here, which is to look for a solution for debugging java appium test.
We can utilize Appium Java REPL inbuilt driver and commands to start a new session and to find elements.
And we can also start a custom session (which is what I was looking for) so we can interact with elements like press a button using TouchAction class (shown below).
Make sure your android phone is connected and adb devices can list your device and appium server is up and running.
Just download the jar file and navigate to folder and run
java -jar appium-repl-0.2.0-BETA1.jar
then do
import static com.mobilebox.repl.Appium.*;
and then create custom session like this
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import io.appium.java_client.*;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.WebElement;
DesiredCapabilities capability = DesiredCapabilities.android();
capability.setCapability("BROWSER_NAME", "Android");
capability.setCapability("VERSION", "7.0");
capability.setCapability("platformName", "Android");
capability.setCapability("appPackage", "your.app.package");
capability.setCapability("appActivity", "your.app.activity");
capability.setCapability("deviceName", "ec8d4453");
nodeURL= "http://localhost:4723/wd/hub" ;
driver = new AndroidDriver(new URL(nodeURL), capability);
TouchAction touchAction = new TouchAction(driver);
WebElement allow= driver.findElementByAndroidUIAutomator(
"new UiSelector().className(\"android.widget.Button\").text(\"ALLOW\")"
);
touchAction.press(allow).release().perform().press(allow).release().perform();
Related
I'm trying to begin using Selenium. I have downloaded the Selenium Stand Alone Server, Selenium for JAVA, and GeckoDriver. I added all of the .jar files from the Stand Alone Server and Selenium for JAVA to my buildpath in Eclipse. When I run my program, I get the follwing error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
FirefoxOptions cannot be resolved to a type
FirefoxOptions cannot be resolved to a type
at check.Selenium_Basic.main(Selenium_Basic.java:14)
My code is below:
package check;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class Selenium_Basic {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\User1\\Documents\\geckodriver-v0.16.1-win32\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //This is the location where you have installed Firefox on your machine
FirefoxDriver driver = new FirefoxDriver(options);
driver.get("http://www.google.com");
}
}
Do you guys know why this doesn't work? Is there a good step by step guide that will allow me to start using this? I have looked at many guides but I can't figure out what I've done incorrectly.
The code looks good. You are missing an import statement for FirefoxOptions. You can add the below line to your code with other import statements & your code should work.
import org.openqa.selenium.firefox.FirefoxOptions;
Also, you don't need to use Selenium StandAlone Server. Selenium Java alone with GeckoDriver would work fine. Make sure that you are using Selenium 3.4, as its compatible with Gecko 16.
You can also check this link for complete setup related steps -
Selenium 3.4 – Complete Guide to the latest Selenium WebDriver
I am trying to test Android device on MAC OS X, using Appium (in Java).
The build path includes these:
java-client-<version>.jar
java-client-<verson>-sources.jar
selenium-java-<version>.jar
selenium-server-standalone-<version>.jar
(the version of the last 2 is the same), and TestNG.
Starting the Appium server (i am using the GUI) works fine and the application (which is already installed on the device) launches. Starting to debug my eclipse project which contains the following lines, i am getting the error for the 3rd line.
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Plus");
AppiumDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
The full error i am getting is:
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. Details: Problem getting session data for driver type AndroidDriver; does it implement 'get driverData'?
You're saying that using the GUI launches the application? If that's the case, and what you're showing in code is your full DesiredCapabilities, then your capabilities would be the problem.
You can see what the capabilities the Appium GUI is using at the top with the text "Launching Appium with command".
If you set those flags in your capabilities, then the driver should connect properly.
You forgot to close the appium session by use driver.close()?
Try to restart your appium server.
P/s: When you don't want to close driver, you need enable Session override in appium GUI settings or add --session-override in appium command line. Then you don't need to restart appium server
I am trying to get started with selendroid and selenium for android virtual devices but im having a few issues. I have all the java/android sdk/eclipse software installed and i can run selenium chromedriver tests fine. BUT when i try to run a test that starts the android virtual device, it never starts and the app doesnt list in the http://localhost:4444/wd/hub/status page.
My generic test is below. If i run this code below, the server will start and i can see my local host data from the status page BUT my app version doesnt get listed. If i run java -jar selendroid-standalone-0.11.0-with-dependencies.jar -app selendroid-test-app-0.11.0.apk then i can see my app listed in the status page. I have tried with the app pre-loaded on the virtual device and also wit the signed app on the virtual device, neither have worked.
I am pretty much at a dead end as where else to look for the solution. I have spent 3-4 days looking for a solution but cant seem to find it. Currently in the java project i have only the selenium and selendroid .jar file dependencies loaded. I have yet to install any jUnit or anything 'test' releated
package testpackage;
import io.selendroid.SelendroidCapabilities;
import io.selendroid.device.DeviceTargetPlatform;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class testClass {
/**
* #param args
*/
public static void runSelendroidTest() throws Exception {
// specify test capabilities (your 'test environment')
SelendroidCapabilities capa = new SelendroidCapabilities("io.selendroid.testapp:0.11.0");
// explicitly state that we want to run our test on an Android API level 17 device
capa.setPlatformVersion(DeviceTargetPlatform.ANDROID17);
// explicitly state that we use an emulator (an AVD) for test execution rather than a physical device
capa.setEmulator(true);
// start a new WebDriver
WebDriver driver = new SelendroidDriver(capa);
// execute a very simple test
WebElement inputField = driver.findElement(By.id("my_text_field"));
Assert.assertEquals("true", inputField.getAttribute("enabled"));
inputField.sendKeys("Selendroid");
Assert.assertEquals("Selendroid", inputField.getText());
// quit testing
driver.quit();
}
}
maybe you wanna make sure if the 'DeviceTargetPlatform.ANDROID17' really targets your device as ANDROID17. That is when you run your test, check the log. If the http://localhost:4444/wd/hub/status works for you, kindly check your device target there.
I had the same issue before and i just figured out that I was using the 'ANDROID18' not ANDROID17.
I'm setting up some Geb tests and I'm getting "geb.driver.DriverCreationException: failed to create driver from callback " errors. Geb will try to launch the testing browser window, but once it does, none of my tests ever run and I get the above error.
I just did an automatic Firefox update to Firefox 32.0.2 so I suspect that the new version and the Selenium Web Driver aren't playing nice any more? How do I fix that?
here is the Geb.config file I've been using? I haven't changed it about 5 months and it's worked fine until now...
import org.openqa.selenium.firefox.FirefoxDriver
import geb.waiting.WaitingSupport
reportsDir = "target/geb-reports"
driver = {
//path is specific to each machine. This is the path to firefox.exe
def pathToBin = 'C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe'
System.setProperty("webdriver.firefox.bin",pathToBin)
def driverInstance = new FirefoxDriver();
driverInstance.manage().window().maximize()
driverInstance
}
It was indeed what I thought it was. Upgraded the jar dependency to Selenium 2.43.1 and it works fine. Was using 2.42.2 before
Is there any way how to run Selenium automation test in Internet Explorer 9 in InPrivate mode with IEDriverServer?
I need to test 2 (two) testcases:
1. browser is closed. Open one window of IE InPrivate mode. Run test.
2. browser is opened in normal mode. Open new window of IE InPrivate mode. Run test.
How should JAVA code look for this tests?
Thank you
public void openBrowserInPrivacyMode(boolean isBrowserActive) {
System.setProperty("webdriver.ie.driver", "path/to/IEDriverServer_x32.exe");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);
сapabilities.setCapability(InternetExplorerDriver.IE_SWITCHES, "-private");
InternetExplorerDriver driver = new InternetExplorerDriver(capabilities);
#Roman's solution is now deprecated.
The new way to do this is as follows:
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);
ieOptions.addCommandSwitches("-private");
InternetExplorerDriver driver = InternetExplorerDriver(ieOptions));
Also, I had problems doing this, until I set a TabProcGrowth registry value. Before doing this I got the following exception:
org.openqa.selenium.SessionNotCreatedException: Unexpected error launching Internet Explorer.
Unable to use CreateProcess() API. To use CreateProcess() with Internet Explorer 8 or higher,
the value of registry setting in
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\TabProcGrowth must be '0'.
I had this with happening with Windows 10 and Selenium 3.14. Curiously enough, setting the TabProcGrowth value also fixed this for me.