I just create a sample code as below which is used to launch the calculator apk file and perform some task
#BeforeSuite
public static void driverInitalize() throws Exception {
try {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android Emulator");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.2.2");
// capabilities.setCapability("browserName", "Chrome");
capabilities.setCapability("appPackage", "com.android.calculator2");
capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");
capabilities
.setCapability("app",
"C:\\Ecare\\Appium\\com.android.calculator2-5.1-1720659-22-minAPI22.apk");
driver = new RemoteWebDriver(
new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} catch (Exception ex) {
ex.printStackTrace();
}
}
#Test
public static void sampleTest1() throws Exception {
try {
// System.out.println(driver.getTitle());
driver.findElement(By.xpath(".//*[contains(text(),'7')]")).click();
driver.findElement(By.xpath(".//*[contains(text(),'+')]")).click();
driver.findElement(By.xpath(".//*[contains(text(),'3')]")).click();
driver.findElement(By.xpath(".//*[contains(text(),'=')]")).click();
String value = driver.findElement(
By.className("android.widget.EditText")).getText();
System.out.print(value);
} catch (Exception ex) {
ex.printStackTrace();
}
}
#AfterSuite
public static void tearDown() throws Exception {
try {
driver.quit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
Whenever I executed the above code will return following exception in appium server as well as in eclipse IDE. Can somebody tell me how can I overcome this issue. It seems to be the session is progress but I'm not sure how to kill the progress session which is started earlier. I tried to start up the appium server as appium --no-reset, and checked in the override existing session as well but no luck.
Failure [INSTALL_FAILED_OLDER_SDK]
> at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:1358:17
> at [object Object].<anonymous> (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:180:9)
> at ChildProcess.exithandler (child_process.js:635:7)
> at ChildProcess.EventEmitter.emit (events.js:98:17)
> at maybeClose (child_process.js:743:16)
> at Process.ChildProcess._handle.onexit (child_process.js:810:5)
> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Remote install failed: pkg: /data/local/tmp/b23beec2f0794d869eb021f75e3791bd.apk\r\r\nFailure [INSTALL_FAILED_OLDER_SDK])","origValue":"Remote install failed: pkg: /data/local/tmp/b23beec2f0794d869eb021f75e3791bd.apk\r\r\nFailure [INSTALL_FAILED_OLDER_SDK]"},"sessionId":null}
> info: <-- POST /wd/hub/session 500 39088.716 ms - 362
Please help me out.
The error you are getting [INSTALL_FAILED_OLDER_SDK] is caused due to the version of android of your avd/device is older than the version being used to compile the code of the app.
Check the target sdk version and the minimum sdk version of the app.
if you have the access to the source code of the app these information will be in the manifest file in the android:minSdkVersion tag.
Related
I'm trying to run tests on GRID3 using appium, but every run i receive this error
public static AndroidDriver<WebElement> initAndroidDriver() throws Exception {
try {
String apkLink = SettingsProvider.getPropertyValue("front.android.apk.link") +
"/" + SettingsProvider.getPropertyValue("front.android.version");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, Platform.ANDROID);
capabilities.setCapability(MobileCapabilityType.APP, apkLink);
capabilities.setCapability(MobileCapabilityType.FULL_RESET, true);
capabilities.setCapability(MobileCapabilityType.NO_RESET, false);
capabilities.setCapability("appium:androidInstallTimeout ", 100000);
return new AppiumBuilder().createAndroidApkDriver(new URL(getSeleniumMobileGridHost()), capabilities);
} catch (MalformedURLException e) {
throw new Exception("Creating ANDROID driver exception " + e.getMessage());
}
}
Error:
java.lang.AssertionError: Initialization Android driver Unable to create a new remote session. Please check the server log for more details. Original error: Unable to parse remote response: <!DOCTYPE html>
Any ideas how ti fix it?
Somebody changed link to grid in property config, added /wd/hub to link and everything started to work
I've wanted to write a Selenium Grid app in Java.
On http://localhost:4444/grid/console it says that the node is connected to the hub.
On the client-side I've wanted to write the following:
try {
DesiredCapabilities capability = DesiredCapabilities.firefox();
WebDriver driver = new RemoteWebDriver(new URL("http://IP of Hub:4444/wd/hub"), capability);
capability.setBrowserName("firefox");
driver.get("https://www.google.com");
} catch (MalformedURLException ex) {
System.err.println("URL Exception: "+ex.getMessage());
}
Unfortunately, the following exception was thrown when running the client app:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: invalid argument: can't kill an exited process
...
Driver info: driver.version: unknown
Provide geckodriver path before initializing a webdriver instance,
try {
DesiredCapabilities capability = DesiredCapabilities.firefox();
System.setProperty("webdriver.gecko.driver", "/PATH_OF_DRIVER/geckodriver.exe");
driver = new RemoteWebDriver(new URL("http://Hub_IP/wd/hub"), capability);
capability.setBrowserName("firefox");
driver.get("https://www.google.com");
} catch (MalformedURLException ex) {
System.err.println("URL Exception: "+ex.getMessage());
}
Solution: There was something wrong with the geckodriver in Linux (node).
I added a node on a Windows PC and it worked.
I am trying to write my first Java Appium test.
Each time I'm running my code the following errors are presented:
org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: connect
....
at MyFirstTest.setupTest(MyFirstTest.java:52)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
Here is my code:
public class MyFirstTest
{
public AppiumDriver<MobileElement> driver;
public WebDriverWait wait;
String usersEmail = "xxxx#gmail.com";
String userPassword = "aaaaaa";
public void login() throws InterruptedException
{
WebElement email = driver.findElement(By.xpath("//android.widget.EditText[contains(#text,'Enter Email')]"));
email.sendKeys(usersEmail);
Sleeper.SYSTEM_SLEEPER.sleep(new Duration(1000, TimeUnit.MILLISECONDS));
driver.findElement(By.xpath("//android.widget.RelativeLayout[contains(#resource-id,'edtPassword')]//android.widget.EditText[contains(#resource-id,'edtText')]")).sendKeys(userPassword);
driver.findElement(By.xpath("//android.widget.Button[contains(#resource-id,'btnLogin')]")).click();
}
#Before
public void setupTest() throws Exception
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platormName", "Android");
capabilities.setCapability("deviceName", "Redmi");
capabilities.setCapability("appPackage","com.ls.stockpair");
capabilities.setCapability("appActivity","com.ls.stockpair.activity.SplashActivity");
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Thread.sleep(8000);
}
#Test
public void go() throws InterruptedException
{
WebElement email = driver.findElement(By.xpath("//android.widget.EditText[contains(#text,'Enter Email')]"));
email.sendKeys(usersEmail);
Sleeper.SYSTEM_SLEEPER.sleep(new Duration(1000, TimeUnit.MILLISECONDS));
driver.findElement(By.xpath("//android.widget.RelativeLayout[contains(#resource-id,'edtPassword')]//android.widget.EditText[contains(#resource-id,'edtText')]")).sendKeys(userPassword);
driver.findElement(By.xpath("//android.widget.Button[contains(#resource-id,'btnLogin')]")).click();
Sleeper.SYSTEM_SLEEPER.sleep(new Duration(2000, TimeUnit.MILLISECONDS));
}
}
Currently I'm starting Appium manually before running the code. Also tried to start Appium from the code - this did not help.
This code worked in the first day I started writing this code however somehow (I really do not know why) this stopped working.
I saw many questions with different answers about this issue in the web but no one helped me so far.
I'm working with a real Android device connected via USB to my Windows machine.
Below is the best solution, You don't need to start appium manually everytime.
public static AndroidDriver<MobileElement> driver=null;
public static AppiumDriverLocalService service=null;
service = AppiumDriverLocalService.buildDefaultService();
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platormName", "Android");
capabilities.setCapability("deviceName", "Redmi");
capabilities.setCapability("appPackage","com.ls.stockpair");
capabilities.setCapability("appActivity","com.ls.stockpair.activity.SplashActivity");
service.start();
driver = new AndroidDriver<MobileElement>(service, capabilities);
Note : If you are using appium version 1.5.3+ then you need to set APPIUM_BINARY_PATH in environmental variable.
e.g. APPIUM_BINARY_PATH=C:\Users\YourUserName\AppData\Roaming\npm\node_modules\appium\build\lib\main.js
For more details on how to set APPIUM_BINARY_PATH please refer below screen shot:
I have been trying to launch the Appium Server programatically and then based on the Process output, would initialize the Android Driver and run some tests. However, everytime the Appium Server is launched from the program, the execution stalls on the initialization of the Android Driver.
Here is my method for Starting the server:
private boolean StartServer(String strCommand)
{
try
{
rtCommand = Runtime.getRuntime();
proc = rtCommand.exec(strCommand);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(proc.getInputStream()));
//Checking output of Appium Server Initialization
String s = null;
while ((s = stdInput.readLine()) != null)
{
System.out.println(s);
if (s.contains("Console LogLevel: debug"));
return true;
}
}
catch (Exception ex)
{
System.out.println("Error in starting Appium Server. Stack Trace below:");
ex.printStackTrace();
return false;
}
return false;
}
Now, My TestNG annotation #BeforeClass holds the following code:
#BeforeClass
public void setUp() throws MalformedURLException
{
StartServer("cmd /c \"\"C:/Program Files (x86)/nodejs/node.exe\" \"C:/Program Files (x86)/Appium/node_modules/appium/lib/server/main.js\" --address 127.0.0.1 --port 4723 --platform-name Android --platform-version 23 --automation-name Appium --log-no-color --udid 3100aeb26c6a2363\"");
FrameworkDriver objFrameworkDriver = new FrameworkDriver();
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "ec5bee97");
capabilities.setCapability("BROWSER_NAME", Android");
capabilities.setCapability("VERSION", "5.1.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.XX.AA");
capabilities.setCapability("appActivity", "com.XX.AA.BB");
strProjectDir = "<MyProjectLoc>";
try
{
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
catch (Exception ex)
{
ex.printStackTrace();
}
System.out.println();
}
The execution halted here:
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Try using something like version 5.1.1, instead of platform-version 23 in your start server command line. (The same version as defined in capabilities in your code)
StartServer("cmd /c \"\"C:/Program Files (x86)/nodejs/node.exe\" \"C:/Program Files (x86)/Appium/node_modules/appium/lib/server/main.js\" --address 127.0.0.1 --port 4723 --platform-name Android --version 5.1.1 --automation-name Appium --log-no-color --udid 3100aeb26c6a2363\"");
Appium wants to the OS version of the Android device instead of the API level
Also, ensure that the device name used while defining capabilities is same as that defined in start server command line.
I am new to Appium and I have installed Appium on ubuntu and make my first test using java command in an Eclipse while running my test I get an error: A new session could not be created.permission to start activity denied.
please Advice.
Here is my code:
public class BoxerTest {
AndroidDriver dr;
#Test
public void setUp() throws MalformedURLException{
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("deviceName","TA09402ERN");
cap.setCapability("platformVersion","5.0.2");
cap.setCapability("platformAndroid","Android");
cap.setCapability("appPackage","com.boxer.browser");
cap.setCapability("appActivity","com.boxer.browser.MainActivity");
dr = new AndroidDriver(new URL ("http://0.0.0.0:4723/wd/hub"), cap);
}
#After
public void End(){
dr.quit();
}
}
Launchable app activity might be wrong. To get the launchable activity, take the APK and run the command aapt dump badging <boxer.apk>