How can I go to the given URL in mobile Chrome browser using c# and appium on real device?

泄露秘密 提交于 2019-12-12 05:28:39

问题


I'm automating mobile web testing on Android real device with Appium and c#. I've seen that there is get method in Java that allows navigation to the given URL, for example:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setPlatform(Platform.ANDROID);
capabilities.setCapability("device", "android");
capabilities.setCapability("app", "chrome");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.get("http://www.google.com");
System.out.println("Android Title is: " + driver.getTitle())

I couldn't find such method in appium dot net driver. Is it my mistake or there is no such method? What is the best way to navigate then?

Here is C# code i use:

[TestClass]
    public class UnitTest1
    {
        private DesiredCapabilities _capabilities;
        private AndroidDriver _driver;

        public void InitializeDriver()
        {
            Console.WriteLine("Connecting to Appium server");
            _capabilities = new DesiredCapabilities();

            _capabilities.SetCapability("deviceName", "Nexus One");
            _capabilities.SetCapability("newCommandTimeout", "300");
            _capabilities.SetCapability(CapabilityType.BrowserName, "Chrome");
            _capabilities.SetCapability(CapabilityType.Version, "5.0.1");
            _capabilities.SetCapability(CapabilityType.Platform, "Android");

            //Application path and configurations
            _driver = new AndroidDriver(new Uri("http://127.0.0.1:4723/wd/hub"), _capabilities);
        }

There is no _driver.Get() or _driver.SendKeys. What should i use?


回答1:


Try this :

driver.sendKeys(URL);



回答2:


The answer could be found via Object Browser (this is what I did). The analogue of Java code looks like:

_navigation = _driver.Navigate();
_navigation.GoToUrl(@"http://stackoverflow.com");

So the full listing will become this:

public void InitializeDriver()
{
    Console.WriteLine("Connecting to Appium server");
    _capabilities = new DesiredCapabilities();

    _capabilities.SetCapability("deviceName", "Nexus One");
    _capabilities.SetCapability("newCommandTimeout", "300");
    _capabilities.SetCapability(CapabilityType.BrowserName, "Browser");
    _capabilities.SetCapability(CapabilityType.Version, "5.0.1");
    _capabilities.SetCapability(CapabilityType.Platform, "Android");

    //Application path and configurations
    _driver = new AndroidDriver(new Uri("http://127.0.0.1:4723/wd/hub"), _capabilities);

    _navigation = _driver.Navigate();
    _navigation.GoToUrl(@"http://stackoverflow.com");
}


来源:https://stackoverflow.com/questions/28917342/how-can-i-go-to-the-given-url-in-mobile-chrome-browser-using-c-sharp-and-appium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!