The problem
Hello.
I have a class in C# to verify if my app is installed or not in my device.
When my device has the app installed, everything works fine. However, when my device does not have the app installed, the system gives me this error message:
Message:
Test method MYAPP.Main.RunTest.RunAllTests threw exception:
System.InvalidOperationException: An unknown server-side error
occurred while processing the command. Original error: Could not find
package com.android.MyApp on the device
How to use and declare the IsAppInstalled?
I’m using VS 2017 Community.
Environment
Appium version (or git revision) that exhibits the issue: Appium
Driver v4.0.30319
Last Appium version that did not exhibit the issue (if applicable):
Same
Desktop OS/version used to run Appium: Windows 10 Pro
Node.js version (unless using Appium.app|exe): Node.js v10.1.0
Mobile platform/version under test: Android 8.0
Real device or emulator/simulator: Real device Samsung S9
Appium CLI or Appium.app|exe: Appium Server v1.8.0
Details
My Capabilities:
public class CapDeviceConfig{
public DesiredCapabilities CapDeviceConfigOptions(){
//set the capabilities (https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md)
DesiredCapabilities cap = new DesiredCapabilities();
cap.SetCapability("automationName", "Appium"); // Which automation engine to use
cap.SetCapability("platformName", "Android"); // Which mobile OS platform to use
cap.SetCapability("platformVersion", "8.0.0"); // Mobile OS version
cap.SetCapability("deviceName", "starlte"); // The kind of mobile device or emulator to use // S9
cap.SetCapability("udid", "2270048324037ece"); // Unique device identifier of the connected physical device
cap.SetCapability("appPackage", "com.android.MyApp");
cap.SetCapability("appActivity", "md5ab6683a3e3c3f0bd6864e3305b4e45c6.SplashScreenActivity");
cap.SetCapability("noReset", "True"); // Don't reset app state before this session.
cap.SetCapability("printPageSourceOnFindFailure", "True"); // When a find operation fails, print the current page source.
return cap;
}
}
Link to Appium logs
https://gist.github.com/pbmzbr/b0638a0237c7d846de2e94000163c1f6
Code To Reproduce Issue
public class AppInstallVerification{
//Creating instance for Appium driver
AppiumDriver<AndroidElement> driverCheck;
CapDeviceConfig cap = new CapDeviceConfig();
EnrollmentTests enrollmentTests = new EnrollmentTests();
InstallApp install = new InstallApp();
public void IsAppInstalled(){
cap.CapDeviceConfigOptions();
driverCheck = new AndroidDriver<AndroidElement>(new Uri("http://127.0.0.1:4723/wd/hub"), cap.CapDeviceConfigOptions());
if (driverCheck.IsAppInstalled("com.android.MyApp"))
{
Console.WriteLine("App is installed!");
enrollmentTests.CodeApplied();
}
else
{
Console.WriteLine("App is not installed!");
install.InstallingApp();
}
}
}
Related
I'm using Appium + C# for mobile Automation and below is my pseudo-code:
AppiumLocalService _appiumLocalService = new AppiumServiceBuilder().UsingAnyFreePort().Build();
_appiumLocalService.Start();
var appiumOptions = new AppiumOptions();
appiumOptions.AddAdditionalCapability(MobileCapabilityType.DeviceName, ConfigurationManager.AppSettings["deviceName"]);
appiumOptions.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Android");
appiumOptions.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, ConfigurationManager.AppSettings["platformVersion"]);
appiumOptions.AddAdditionalCapability(MobileCapabilityType.NoReset, true);
appiumOptions.AddAdditionalCapability(MobileCapabilityType.App, ConfigurationManager.AppSettings["app"]);
appiumOptions.AddAdditionalCapability("appPackage", ConfigurationManager.AppSettings["appPackage"]);
appiumOptions.AddAdditionalCapability("appActivity", ConfigurationManager.AppSettings["appActivity"]);
appiumOptions.AddAdditionalCapability("newCommandTimeout", 5000);
appiumOptions.AddAdditionalCapability("autoLaunch", false);
_driver = new AndroidDriver<AppiumWebElement>(appiumOptions);
I'm getting the following error message:
{"Invalid server instance exception has occurred: There is no installed nodes! Please install node via NPM (https://www.npmjs.com/package/appium#using-node-js) or download and install Appium app (http://appium.io/downloads.html)"}
Below you can see which settings I have already installed
Try installing Appium with npm install -g appium.
Then try again.
I have just started learning Appium testing using C#. I made simple program using Visual Studio to just open app from Emulator.
When I run my code I am getting this error
Message: System.UriFormatException : Invalid URI: The Authority/Host
could not be parsed. TearDown : System.NullReferenceException : Object
reference not set to an instance of an object.
This is my code
public class UnitTest1
{
private AndroidDriver<AndroidElement> driver;
private DesiredCapabilities capabilities;
[SetUp]
public void InItDriver()
{
capabilities = new DesiredCapabilities();
capabilities.SetCapability("PlatformName", "Android");
capabilities.SetCapability("deviceName", "Pixel_API_27:5554");
capabilities.SetCapability("appPackage", "com.sisapp.in.tulip");
capabilities.SetCapability("appActivity", "SplashActivity");
driver = new AndroidDriver<AndroidElement>(new Uri("https:127.0.01:4723/wd/hub"), capabilities);
}
[Test]
public void Test1()
{
Assert.IsNotNull(driver);
System.Threading.Thread.Sleep(2000);
}
[TearDown]
public void CloseTest()
{
driver.Quit();
}
}
Note: I did not installed anything like Appium Server in my machine.
These packages I have installed in my project. How can I solve this issue?
You must install and start Appium server in your pc. Then you will be able to run appium test.
Steps to install appium server
Download and install nodejs from here
install appium server from cmd using:
npm install -g appium
To start appium server:
appium -a 127.0.0.1 -p 4723 --session-override
In your code code instead of Uri try to use URL. Also change your url as follow:
driver = new AndroidDriver(new URL("https://127.0.0.1:4723/wd/hub"), capabilities);
Edit: Above issue is going to solve by this workaround regardless what other issues you are getting :).
I have a .NET-wrapper library based on .NET Framework v4.6.1, which invokes UWP OCR API. It contains only one class with one function in it, code is below
public static async Task<string> ExtractText(Stream stream, string language)
{
using (IRandomAccessStream uwpStream = new InMemoryRandomAccessStream())
{
byte[] input = new byte[stream.Length];
stream.Read(input, 0, input.Length);
uwpStream.AsStreamForWrite().Write(input, 0, input.Length);
uwpStream.AsStreamForWrite().Flush();
uwpStream.Seek(0);
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(uwpStream);
SoftwareBitmap bitmap = await decoder.GetSoftwareBitmapAsync();
OcrEngine engine = OcrEngine.TryCreateFromLanguage(new
Language(language));
uwpStream.Dispose();
if (engine != null)
{
OcrResult result = await engine.RecognizeAsync(bitmap);
return result.Text;
}
else
{
throw new NullReferenceException("Language is not supported");
}
}
}
Project has links to following UWP libraries: Windows.WinMD, Windows.Foundation.FoundationContract.winmd, Windows.Foundation.UniversalApiContract.winmd. I found their location via object browser in Visual Studio, copied them from their original location to subfolder in my project and then linked them.
My app runs ok on my local machine and UWP OCR Engine works fine.
Then I deploy my library and an application, which uses it, on my virtual machine, which has Windows Server 2012 R2 on it with installed .NET Framework and installed Windows 10 SDK.
My program fails during runtime with the exception:
Could not find Windows Runtime type "Windows.Graphics.Imaging.SoftwareBitmap"
To solve the problem I tried to reinstall Windows 10 SDK on my virtual server and checked that versions match exact versions on my development machine.
It seems like some of the .winmd libraries does not load in runtime.
I expect my program to run successfully on another machine in release mode.
It works on development machine fine.
However, I am new to UWP, so maybe initial information is not enough to solve the problem, but I'm ready to provide more.
Any help would be appreciated
I was able to make my UWP OCR work on Windows Server 2019
It seems like Windows Server 2012 R2 does not support all the functional of Windows 10 SDK
At least my program could not load all the .winmd files required in runtime
Migration to Windows Server 2019 makes it work without any problems
I'm running Appium 1.6.1 on Windows 10, and I'm trying to automate Chrome on a real device (in this instance a Samsung Galaxy S7 running Android 7.0). I'm using C# and visual studio. My code looks like the below:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Appium.Android;
namespace MobileBrowserTesting{
[TestClass]
public class UnitTest1{
AppiumDriver<IWebElement> Driver;
[TestMethod]
public void TestMethod1(){
DesiredCapabilities caps = new DesiredCapabilities();
caps.SetCapability("deviceName", "hero2lteskt");
caps.SetCapability("udid", "ce11160b3889d43005"); //Give Device ID of your mobile phone
caps.SetCapability("browserName", "Chrome");
//Launch the Android driver
Driver = new AndroidDriver<IWebElement>(new Uri("http://127.0.0.3:4723/wd/hub"), caps);
Driver.Navigate().GoToUrl("http://www.google.com");
string url = Driver.Url;
bool viewable = Driver.FindElement(By.Id("q")).Displayed;
}
}
}
Chrome launches, however it simply sits at "data;" with a blank screen and doesn't progress to the website. The last step in the Appium view is:
[JSONWP Proxy] Proxying [POST /session] to [POST
http://127.0.0.1:8001/wd/hub/session] with body: {"desiredCapabilities":
{"chromeOptions":
{"androidPackage": "com.android.chrome","androidDeviceSerial":"ce11160b3889d43005"}}}
[HTTP] <-- POST /wd/hub/session - - ms - -
And visual studio times out with the error message:
Message: Test method MobileBrowserTesting.UnitTest1.TestMethod1 threw
exception:
OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://127.0.0.3:4723/wd/hub/session timed out after 60 seconds. ---> System.Net.WebException: The operation has timed out
After a while Appium times out with:
[W3C] Encountered internal error running command: Error: Failed to start
Chromedriver session: An unknown server-side error occurred while processing
the command. (Original error: unknown error: Device ce11160b3889d43005 is
already in use
Appium is launched in admin mode, with "Allow session override" ticked under Advanced.
The chromedriver being used is the latest one (2.39) and the version of chrome on the device is 66.0.3359.158 so it should be compatible.
Any ideas why it seems to hang/not interact with Chrome?
Cheers in advance
I'm using the C# bindings for Selenium and trying to get a simple automated test in Microsoft Edge working.
class Program
{
static void Main(string[] args)
{
EdgeOptions options = new EdgeOptions();
options.PageLoadStrategy = EdgePageLoadStrategy.Eager;
RemoteWebDriver driver = new EdgeDriver();
driver.Url = "http://bing.com/";
}
}
But the program halts on the initialisation of the EdgeDriver, the edge browser launches but the url never changes to "bing.com".
Has anyone else experienced this?
I have faced the same issue. I followed the below steps to resolve it :-
Download the correct Microsoft WebDriver server version for your build.
How to find your correct build number :-
1- Go to Start > Settings > System > About and locate the number next to OS Build on the screen. This is your build number. Having the correct version of WebDriver for your build ensures it runs correctly.
2- Run this command systeminfo | findstr /B /C:"OS Version" this will give the output like OS Version: 10.0.10586 N/A Build 10586. Here is build number is 10586
You need to check your Windows OS build number and download appropriate .msi and install it.
Provide the Syetem property where MicrosoftWebDriver.exe installed to webdriver.edge.driver.
Note :- The Default installed location of the MicrosoftWebDriver.exe :-
for 64 bit is C:\Program Files (x86)\Microsoft Web Driver
for 32 bit is C:\Program Files\Microsoft Web Driver
Hope it will work...:)
This happens when your system does not match the webdriver version... Determine which release of Windows 10 you are using... then go here and download same release..
https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver
Here's what the error looks like when the versions don't match.
Selenium will Hang
EdgeOptions options = new EdgeOptions();
options.PageLoadStrategy = EdgePageLoadStrategy.Eager;
RemoteWebDriver driver = new EdgeDriver();
driver.Url = "http://bing.com/";
Results in this exception with Edge still up and on the Bing page
Exception Thrown
changing the code to this, with no options:
var driver = new EdgeDriver();
driver.Url = "http://bing.com/";
Results in this:
Exception thrown: 'System.InvalidOperationException' in WebDriver.dll
And this in the console.
Something's not right with the MicrosoftWebDriver.Exe which was downloaded from here. https://www.microsoft.com/en-us/download/details.aspx?id=48212 and installed into the Program Files folder by default. Here's screenshot of add/remove programs. System is Windows 10 PRO 64 bit.
Note I did not try the 32 bit version