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 :).
Related
I created a very simple C# project to test Selenium and Chrome Driver, but when I run it, it gets stuck at the very first line, ie. creating ChromeDriver object.
I have set up as following:
.NET Core 3.1 console app (also tried .NET 4.7)
Installed Selenium.WebDriver 3.141.0 and Selenium.WebDriver.ChromeDriver 87.0.4280.8800.
My Chrome version is "Version 87.0.4280.88 (Official Build) (64-bit)". I have double-checked compatibility with Chrome and ChromeDriver.
Code:
using OpenQA.Selenium.Chrome;
namespace MyFirstSelenium
{
class Program
{
static void Main(string[] args)
{
ChromeDriver chrome = new ChromeDriver();
chrome.Navigate().GoToUrl("https://www.google.co.jp/");
}
}
}
visual studio screen
chromedriver.exe is copied to the debug folder as expected, so I assume the problem is neither compatibility nor path.
chromedriver
When I run the code, the result is an empty window with 'data' in the address bar. No error is thrown. I have searched for several hours and found some articles, but most of them are old and none of these answers led to success.
Any help is appreciated. Thank you.
Added chromedriver.exe verbose console output.
#Piotr M.
chromedriver console
logfile
https://drive.google.com/file/d/1ECOS8E55aaTFV63e8P-7n6uRVcf49PRN/view?usp=sharing
New code
Works when I first execute "chromedriver.exe --verbose --log-path=chromedriver.log", but without it, it throws WebDriverException.
OpenQA.Selenium.WebDriverException: 'A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL localhost:9515/session. The status of the exception was UnknownError, and the message was: No connection could be made because the target machine actively refused it. No connection could be made because the target machine actively refused it.'
var chromeOptions = new ChromeOptions();
chromeOptions.BrowserVersion = "87";
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:9515"), chromeOptions);
Possibly a classic case of cyclic redundancy.
chrome is a reserved word, you may have to change the variable name to something else e.g. chromex. So your effective line of code will be:
ChromeDriver chromex = new ChromeDriver();
Additional Consideration
Consider the following aspects aswell:
Instead of using the ChromeDriver class use the IWebDriver interface.
IWebDriver driver = new ChromeDriver();
Instead of the partial url google.co.jp/ you need to pass the complete url through GoToUrl() as follows:
driver.Navigate().GoToUrl(#"https://www.google.co.jp/");
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.
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();
}
}
}
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 just started using visual studio 2015 & c# language so I'm a complete newbie. anyway I was trying to write a web testing project with selenium (references) in vs2015 and the first few tutorials were relatively easy to understand, that's what I got:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support;
namespace testsite
{
[TestClass]
public class firsttest
{
IWebDriver driver;
String url = "http://www.somewabpage.com";
[TestInitialize]
public void setup()
{
//Starting the browser and visiting the site
driver = new ChromeDriver();
driver.Navigate().GoToUrl(url);
}
[TestCleanup]
public void Cleanup()
{
//after the test
driver.Quit();
}
[TestMethod]
public void testtingsite()
{
//Here we write the actual test
}
}
}
I know it's not much, but the problem is when ever I go to test explorer >> run all then I get this:
------ Run test started ------
Cannot discover test extensions installed by NuGet. The NuGet service is not available. Tests may not be found due to missing test adapter extensions.
NUnit VS Adapter 2.0.0.0 executing tests is started
Loading tests from C:\Users\kkkkkk\Documents\Visual Studio 2015\Projects\testsite\testsite\bin\Debug\testsite.dll
Run started: C:\Users\kkkkkk\Documents\Visual Studio 2015\Projects\testsite\testsite\bin\Debug\testsite.dll
NUnit VS Adapter 2.0.0.0 executing tests is finished
========== Run test finished: 1 run (0:00:06.5556584) ==========
White it should open the chrome browse, visit the url and then quits chrome, which doesn't happen at all. I re-tested it again with the same result only this time it says in the test explorer window that the test has failed and that's it, when I click on the testsite below the failed test (still in the test explorer window) i get the following message :
Test Name: testtingsite
Test FullName: testsite.firsttest.testtingsite
Test Source: c:\users\kkkkkk\documents\visual studio 2015\Projects\testsite\testsite\UnitTest1.cs : line 34
Test Outcome: Failed
Test Duration: 0:00:00.1350487
Result StackTrace:
à OpenQA.Selenium.DriverService.FindDriverServiceExecutable(String executableName, Uri downloadUrl) dans c:\Projects\webdriver\dotnet\src\webdriver\DriverService.cs:ligne 243
à OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService() dans c:\Projects\webdriver\dotnet\src\webdriver\Chrome\ChromeDriverService.cs:ligne 146
à OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options) dans c:\Projects\webdriver\dotnet\src\webdriver\Chrome\ChromeDriver.cs:ligne 80
à OpenQA.Selenium.Chrome.ChromeDriver..ctor() dans c:\Projects\webdriver\dotnet\src\webdriver\Chrome\ChromeDriver.cs:ligne 71
à testsite.firsttest.setup() dans c:\users\kkkkkk\documents\visual studio 2015\Projects\testsite\testsite\UnitTest1.cs:ligne 19
Result Message: Initialization method testsite.firsttest.setup threw exception. OpenQA.Selenium.DriverServiceNotFoundException: OpenQA.Selenium.DriverServiceNotFoundException: The chromedriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html..
okay that's the message, any ideas on how to solve the issue I really need help );
modification_1
so I've modified the code (thanks to #Leon) I added the following string DRIVER_PATH = #"C:\Projects\webdriver\dotnet\src\webdriver\chrome\chromedriver"; to [TestClass] right below the string url = "http://..."; and also add DRIVER_PATH like this driver = new ChromeDriver(DRIVER_PATH); in the [TestInitialize] but it's still not running the chrome browser!!?
You need download chrome driver.
chrome driver link
string DRIVER_PATH = #"C:\...\chromedriver";
IWebDriver driver = new ChromeDriver(DRIVER_PATH);
driver.Navigate().GoToUrl(url);
so the problem was like #leon mentioned it in the chromedriver, but although I used his path method (described in modification_1) it didn't work, what actually did work and solved my problem (without changing the first code, before mofication_1) was the installation of the selenium chromedriver from visual studio 2015, I went to references >> right click >> go to manage Nuget package >> and then typed selenium chromedriver in the search bar and boom all I had to do was click on install, internet connection was required. if you can't see the nuget manage packages then you need to download and install it and then restart visual studio to see it.
Just add the driver reference as per your browser specification like chromedriver, edgedriver. Please note "not mention any driver path".
namespace UnitTestProject3
{
public class UnitTest1
{
IWebDriver wb;
String url = "http://www.yahoo.com";
[Fact]
public void TestMethod1()
{
wb = new ChromeDriver();
wb.Navigate().GoToUrl(url);
}
}
}