Selendroid not starting virtual device - java

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.

Related

Run as java application brings up select java application screen, no further instruction

Asking because I'm following Guru99's time sensitive selenium course and the code that I have downloaded as part of my project will not run as a java application.
It is supposed to be ran with only this code:
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestScript01 {
public static void main(String[] args) throws Exception {
WebDriver driver = new ChromeDriver();
String baseUrl = "http://www.demo.guru99.com/V4/";
// launch Firefox and direct it to the Base URL
driver.get(baseUrl);
// Enter username
driver.findElement(By.name("uid")).sendKeys("xxxx");
// Enter Password
driver.findElement(By.name("password")).sendKeys("xx");
// Click Login
driver.findElement(By.name("btnLogin")).click();
}
}
However, I have added: import org.openqa.selenium.WebDriver; and System.setProperty("webdriver.chrome.driver",
"C://selenium/chromedriver.exe");
I've also not included my real username and password in code above
I have downloaded Chrome driver to the selenium folder in my C drive
I was trying to run from firefox initially but was stuck on Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms errors, which I downgraded my firefox for as that worked for many on this site, but it was still giving me the same error so I switched to Chrome, which selenium seems to prefer. I'm using the latest version of Chrome and Firefox 47.0
I'm using selenium 3.6.0 and jdk 1.8.0_111
When trying to run as an application, according to the instructions, I seem to be in a loop where I keep getting this screen:
I have never had to select an option in order to run a selenium script before, not sure why I'm getting it now or what I'm supposed to select if any.
I have googled but it seems that most instructions for running selenium tests do not include this pop-up. I thought that instantiating a new WebDriver object and selecting the right imports were enough, what am I missing?
You havn't mentioned the Selenium, ChromeDriver, Chrome Browser and JDK versions. Assuming you are using the latest version of Selenium, ChromeDriver, Chrome Browser and JDK, I would suggest a few steps as follows:
Instead of import org.openqa.selenium.*; always use import org.openqa.selenium.WebDriver; and the required ones.
While working with Selenium 3.x (Java) it is mandatory to mention the following line :
System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver.exe");
In this line you have to either use single front slashes / or you have to use escaped back slashes \\
The screen with Select Java Application indicates there are multiple overlapping imports in your project or methods from overlapping jars. We need to keep only the used imports in your script & used jars in your project and remove the other imports/jars from your script/project to keep it simple.
From your IDE take a Project -> Clean for all the projects and keep Build Automatically selected.
Error Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms can arise for many reasons. The best remedy is to uninstall the Browser with Revo Uninstaller, Run CCleaner to wipe out all the rotten OS stuffs and take a system reboot and trigger your Test.

Eclipse java appium test debug

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();

Could not start Selenium session: in Junit 3.8.2 test and selenium 3.4 on linux

My environment:
linux ubuntu
selenium-html-runner-3.4.0.jar
selenium-java-3.4.0
selenium-server-standalone-3.4.0.jar
to build I do:
javac -cp "/usr/share/java/junit.jar:/home/me/ushare/hobo/selenium/selenium-html-runner-3.4.0.jar:." TestHobo2.java
to run selenium-server:
java -jar selenium-server-standalone-3.4.0.jar
to run the test I do:
java junit.textui.TestRunner TestHobo2
and I get:
java.lang.RuntimeException: Could not start Selenium session:
at
com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:114)
at
com.thoughtworks.selenium.SeleneseTestBase.setUp(SeleneseTestBase.java:139)
at
com.thoughtworks.selenium.SeleneseTestBase.setUp(SeleneseTestBase.java:108)
at
com.thoughtworks.selenium.SeleneseTestCase.setUp(SeleneseTestCase.java:113)
at TestHobo2.setUp(TestHobo2.java:10) at
com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:289)
Caused by: com.thoughtworks.selenium.SeleniumException:
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:111)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:105)
at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:277)
at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:239)
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:105)
... 15 more
Here is my test case:
import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
public class TestHobo2 extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://www.example.com/", "*chrome");
}
public void testGetLink() throws Exception {
selenium.type("name=p_loc", "groove");
selenium.click("css=input[type=\"Submit\"]");
selenium.waitForPageToLoad("30000");
}
}
Edit 2017/07/20 More info:
I am using Firefox version 52.0.2 (64-bit).
Should I be getting the following after the build?
Note: TestHobod2.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
geckodriver -v
1500554646753 geckodriver INFO geckodriver 0.18.0
1500554646753 webdriver::httpapi DEBUG Creating routes
1500554646764 geckodriver ERROR Address in use (os error 98)
Are you sure that you have properly defined on which ip address and port is selenium running? Run your selenium server and put http://127.0.0.1:4444/wd/hub/ link into your browser. Try to create new session manually (click on create session and select browser, see image below), new browser blank window should appear. If this is working correctly than selenium server is ok. Then there can be problem with connection between server and your runner.
screen of selenium hub with create session option
Do you have correctly setup selenium driver? For example I'm using
new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub/"),DesiredCapabilities.firefox())
EDIT1: Show example of setUp method which create instance of RemoteDriver, create new browser session and fill url.
WebDriver driver = new RemoteWebDriver(new URL("http://192.168.4.52:4444/wd/hub"), DesiredCapabilities.firefox());
driver.manage().window().maximize()//maximaze window as possible
driver.get("www.google.com"); //navigate to google, i.e. fill url into opened session
Looking at the codebase, and trying to map your shared test code, seems to suggest that you will end up invoking a Firefox browser. The underlying implementation in Selenium has ensured that this will cause your test code to resort to perhaps using firefox.
Can you please ensure that you have made geckodriver downloaded and made available in your PATH variable ?
If that doesn't fix the problem (which could mostly be due to mismatch between the firefox version that you have in your desktop and the geckodriver version ), you can try switching to using Google Chrome.
You can switch to google chrome by
Changing : setUp("http://www.example.com/", "*chrome");
To : setUp("http://www.example.com/", "*googlechrome");
And see if that spins off the browser (For google chrome you would need to ensure you have chromedriver downloaded and made available in your local machine)

Selenium in java eclipse linux

I have the following error
and here is my code
import org.openqa.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class io {
/**
* #param args
*/
public static void main(String[] args) {
WebDriver driver=new ChromeDriver();
}
}
I mention that this error appear only when a do "new ChromeDriver()" .If i let without that it don't do that and i don't know what i need to do to solve it.Please help.
EDIT: After i dowloaded the chrome driver when i execute the program it works fine but when i am debugging it suspend.Why this happens?
You have to set the System property before creating an instance of the chrome driver. Download chromedriver in your machine and add below line to your code before initializing the chromedriver.
System.setProperty("webdriver.chrome.driver","<path to chromedriver>");
Hope it helps.
Take a look at my project, https://github.com/codezombies/easytest. One of the methods on my project makes chrome driver initialization happens before the tests run ( actually upon driver type selection ). With that said, i embedded the 3 types of chrome driver on different OS, and it should work as well on linux.

Webdriver MS Edge browser does not get URL

I tried to navigate URL with MS Edge Browser but it giving me error.
My Environment is as follows:
Windows: 10 64x pro.
Browser: MS Edge 25.10586.0.0
Selenium WebDriver: 2.48.2
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
public class edgeBrowser {
public static void main(String[] args) {
System.setProperty("webdriver.edge.driver",
"C:\\Program Files (x86)\\Microsoft Web Driver\\MicrosoftWebDriver.exe");
WebDriver driver = new EdgeDriver();
driver.get("http://www.google.com");
}
}
MS edge browser opens but it does not navigate to google.com and I received following error
Received a request for http://localhost:17347/session
Existing Microsoft Edge process (pid: 64400) terminated forcibly.
Waiting for new request...
Received a request for http://localhost:17347/shutdown
Stopping server.
Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException: null (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 6.79 seconds
I had the same issue (if I recall) and the solution for me was to install the driver presented as:
For the latest preview build from the Windows Insider Program, install
this version of Microsoft WebDriver
Listed here:
WebDriver for Microsoft Edge (Windows)
We had the same issue and after so much of struggle we found the solution which works fine for us.
Microsoft has made Microsoft WebDriver a Feature on Demand (FoD) to make it easier to get the right version for your device.
The simplest way to get started is to enable Developer Mode. Open the Settings app and go to “Update & Security,” “For developers,” and select “Developer Mode.” The appropriate version of WebDriver will be automatically installed.
You can also install a standalone version of WebDriver in one of two ways:
Search “Manage optional features” from Start, then select “Add a Feature,” “WebDriver.”
Install via DISM by running the following command in an elevated command prompt:DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
You can checkout the complete steps in this blog : https://techminionsite.com/fix-for-microsoft-webdriver-windows-10-issue/

Categories

Resources