Upgrading from Selenium.Webdriver 2.44 to 2.46 throws a NullReferenceException

We've just started working with Appium at my company, using it to automate testing on websites and webapps.

Testing Framework = Nunit 2.6.4
Language used     = C#
Mobile Device     = Samsung Galaxy S4
Android version   = 5.0.1

      

I've used Selenium and Nunit for desktop testing before on a simple website using the [Test], [TestCase] ​​and [TestCaseSource] attributes in my tests.

Following the guidelines in the answer article at: How to integrate Appium with C #?

(A quicker article link is here: http://blogs.technet.com/b/antino/archive/2014/09/22/how-to-set-up-a-basic-working-appium-test-environment.aspx )

The linked team created a solution that would make easy navigation to StackOverflow, click the link and submit:

namespace AppiumTests
{
using System;
using NUnit.Framework;
using AppiumTests.Helpers;
using AppiumTest.Framework;
using OpenQA.Selenium; /* Appium is based on Selenium, we need to include it */
using OpenQA.Selenium.Appium; /* This is Appium */
using OpenQA.Selenium.Appium.Interfaces; /* Not needed for commands shown here. It might be needed in single tests for automation */
using OpenQA.Selenium.Appium.MultiTouch; /* Not needed for commands shown here. It might be needed in single tests for automation */
using OpenQA.Selenium.Interactions; /* Not needed for commands shown here. It might be needed in single tests for automation */
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Appium.Android;

[TestFixture]
public class AndroidAppiumTestSuite
{
    private AppiumDriver driver;

    private static Uri testServerAddress = new Uri(TestServers.WindowsServer);
    private static TimeSpan INIT_TIMEOUT_SEC = TimeSpan.FromSeconds(180); /* Change this to a more reasonable value */
    private static TimeSpan IMPLICIT_TIMEOUT_SEC = TimeSpan.FromSeconds(10); /* Change this to a more reasonable value */

    [SetUp]
    public void BeforeAll()
    {
        DesiredCapabilities capabilities = new DesiredCapabilities();



        TestCapabilities testCapabilities = new TestCapabilities();

        //testCapabilities.App = "";
        testCapabilities.AutoWebView = true;
        testCapabilities.AutomationName = "<just a name>";
        testCapabilities.BrowserName = "Chrome"; // Leave empty otherwise you test on browsers
        testCapabilities.DeviceName = "Needed if testing on IOS on a specific device. This will be the UDID";
        testCapabilities.FwkVersion = "1.0"; // Not really needed
        testCapabilities.Platform = TestCapabilities.DevicePlatform.Android; // Or IOS
        testCapabilities.PlatformVersion = "5.0.1"; // Not really needed


        testCapabilities.AssignAppiumCapabilities(ref capabilities);
        driver = new AndroidDriver(testServerAddress, capabilities, INIT_TIMEOUT_SEC);
        driver.Manage().Timeouts().ImplicitlyWait(IMPLICIT_TIMEOUT_SEC);
    } 

    [TearDown]
    public void AfterAll()
    {
        TestContext.CurrentContext.Result.ToString();
        driver.Quit(); // Always quit, if you don't, next test session will fail
    }

    /// <summary>
    /// Just a simple test to heck out Appium environment.
    /// </summary>
    [Test]
    public void CheckTestEnvironment()
    {
        driver.Navigate().GoToUrl("http://stackoverflow.com");
        driver.FindElementByCssSelector("body > div.topbar > div.network-items > div.login-links-container > a").Click();
        Assert.AreEqual("Log in using any of the following services", (driver.FindElementByCssSelector("h2.title")).Text);
    }    

      

Many thanks to Andrea Tino for this starting point.

Now it worked well and my colleague who asked this and showed it to me went on vacation leaving me the task of adding to our existing tests and setting the bits here and there.

I added to my test class that requires Webdriver.Support pacakge to be installed which depends on Webdriver> = 2.46.0

Now when I run my code I am getting a link exception on this line: driver = new AndroidDriver(testServerAddress, capabilities, INIT_TIMEOUT_SEC);

This is the error I am getting:

AppiumTests.AndroidAppiumTestSuite.CheckTestEnvironment: SetUp : System.NullReferenceException : Object reference not set to an instance of an object. TearDown : System.NullReferenceException : Object reference not set to an instance of an object.

So, I thought that something in 2.46.0 meant that I needed to provide one more opportunity, but I've been banging my head about it for two days now without any success.

I have a screenshot of the appium server communication, but I cannot link the images, but XD, so here it is pasted in:

information: [debug] The device is started! Ready for commands

info: [debug] Set the default command timeout to 60 seconds

info: [debug] Start an Appium session with sessionId 4575272bba7d11c85414d48cf53ac8e3

information: <- POST / wd / hub / session 303 10828.204 ms - 70

info: β†’ GET / wd / hub / session / 4575272bba7d11c85414d48cf53ac8e3 {}

info: Proxying [GET / wd / hub / session / 4575272bba7d11c85414d48cf53ac8e3] in [GET http://127.0.0.1:9515/wd/hub/session/4575272bba7d11c85414d48cf53ac8e3] with body: {}

info: Received a response with status 200: {"sessionId": "4575272bba7d11c85414d48cf53ac8e3", "status": 0, "value": {"acceptSslCerts": true, "applicationCacheEnabled": false, "browserConnectionEnabled": false, "browserName": "chrome" "chrome": {}, "cssSelect ...

information: <- GET / wd / hub / session / 4575272bba7d11c85414d48cf53ac8e3 200 6.770 ms - 506

info: β†’ POST / wd / hub / session {"wishCapabilities": {"javascriptEnabled": true, "device": "Android", "platformName": "Android", "deviceName": "d5cb5478", "browserName": "Chrome", "platformVersion": "5.0.1", "browserVersion": "43.0.2357.93"}}

Error: Failed to start Appium session, error was: Error: Requested a new session but it continued.

So, I can see that it is trying to start a new session when I already started it, but I cannot figure out the reason!

+3


source to share


1 answer


So how to get around Appium's specific half of the problem - I don't have an answer for yours NullReferenceException

.


This Appium error occurs when the port you are trying to run Appium WebDriver on to is already in use.

To manually fix this

  • You can do $telnet ip port

    to figure out what Process ID

    you need to kill.

    • You can find the address / port by checking the value it returns for new Uri(TestServers.WindowsServer);

      .
  • Quit all emulators

  • Once you have it PID

    , you can $kill -9 pid

    build and run your Appium server as usual.




Correct solution

If you have this problem regularly, it might be because your script ends without exiting Appium WebDriver.

Typically, you put the break code for WebDriver ( driver.quit()

) in @After

your tests section or in the base class TestCase

.

I see you have a rift section - so maybe you got into this bad state during the previous session? Either way, a manual fix should get you back online.

+1


source







All Articles