I'm using Appium, the test automation tool for native and hybrid apps on mobiles to test a mobile web application. So I'm using chrome to be the browser and I configured everything, even I tried for an application on the mobile itself(native) and everything worked.
The problem comes when I try to test a mobile web app, the web page opens with data; and crashes immediately and the tests couldn't run.
Here's a snap of my code:
namespace AppiumTest
{
[TestFixture]
public class Appium_Test
{
//public IWebDriver driver;
private AppiumDriver<AndroidElement> driver;
[SetUp]
public void Setup()
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability("device", "Android");
capabilities.SetCapability("browserName", "chrome");
capabilities.SetCapability("deviceName", "Huawei Mate 8");
capabilities.SetCapability("platformName", "Android");
capabilities.SetCapability("platformVersion", "6.0");
//For mobile web application
driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities, TimeSpan.FromSeconds(180));
}
[Test]
public void Browser_Test()
{
driver.Navigate().GoToUrl("www.github.com");
driver.FindElement(By.ClassName("octicon octicon-three-bars")).Click();
}
[TearDown]
public void Teardown()
{
driver.Quit();
}
}
}
Install the latest Chrome version to your device/emulator (to avoid the infinite loop and Chrome crashing on start which can be caused by the not supported Chrome version in the chromeDriver inside Appium) and use the following capabilities:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "6.0");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554";
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");`
The key to the right capabilities lies in the following package:
io.appium.java_client.remote.MobileCapabilityType`
If you don't use it, you will use the basic selenium capabilities which are not prepared for that kind of usage.
Related
I cannot get selenium to find my webdrivers, wether it be firefox or chrome. I have tried downloading the dirvers manually and with the NuGet package manager, neither of them are working for me in C# but with python they work fine.
C# code that does not work. Gives out error:
Exception thrown: 'OpenQA.Selenium.DriverServiceNotFoundException' in WebDriver.dll
An exception of type 'OpenQA.Selenium.DriverServiceNotFoundException' occurred in WebDriver.dll but was not handled in user code
The file C:/webdrivers/geckodriver.exe does not exist. The driver can be downloaded at https://github.com/mozilla/geckodriver/releases
Commeted code, found on some old stackoverflow question did not work either
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
class Scraper
{
/*
private static IWebDriver Driver { get; set; }
public static IWebDriver Init()
{
//System.Environment.SetEnvironmentVariable("webdriver.gecko.driver", #"C:\webdrivers\geckodriver.exe");
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(#"C:\webdrivers");
service.FirefoxBinaryPath = #"C:\Program Files\Mozilla Firefox\firefox.exe"; // May not be necessary
FirefoxOptions options = new FirefoxOptions();
TimeSpan time = TimeSpan.FromSeconds(10);
Driver = new FirefoxDriver(service, options, time);
return Driver;
}
*/
IWebDriver driver;
public void StartScraping()
{
//driver = Init();
driver = new FirefoxDriver(#"C:/webdrivers/");
}
}
Calling the StartScraping() from UWP applications MainPage.xaml.cs constructor
Python code that works just fine
import selenium
from selenium.webdriver import Firefox, Chrome
def startf():
driverf = Firefox("C:/webdrivers/")
driverf.get("https://www.google.com")
startf()
Some have said that I should add the webdrivers directory to PATH, that I've done as well but nothing changed
EDIT:
After returning to this problem a couple of days later and testing selenium with just a console application and it working properly there.
This would seem to be a problem with me using a blank Universal Windows Platform application instead of a Console App. Is there a way to "attach" or open a console window inside a UWP application? Or could that even fix this issue? if not, can I somehow open similar XML form window from a console application?
The best way to get rid of this is to use Path.DirectorySeparatorChar in the path instead of using / or \\.
You can use it like:
separator = Path.DirectorySeparatorChar;
path = $"C:{separator}webdrivers{separator}";
And now you can use this path while running firefox.
I'm trying to run below code within a controller in Asp.net MVC 5:
var driver = new FirefoxDriver(firefoxOptions);
It works when I'm using IIS Express, but the browser is not opened when I'm using IIS. Do we need to do something in IIS setting to make it work?
Try using RemoteWebDriver rather than FirefoxDriver
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability(CapabilityType.BrowserName, "firefox");
string serverURL = "http://localhost:4444/wd/hub";
driver = new RemoteWebDriver(new Uri(serverURL), capabilities);
I have created test suite with 10 test cases using Visual Studio 2015. Tests are implemented in C# using WebDriver.
Now, my aim is to make a concept of distributed testing in Selenium using Grid technology.The Test suite to be run in 3 different browsers:IE, Chrome, Firefox parallely.
I think my grid setup is successful, but I need to expand my tests implemented in WebDriver. I found just a few tutorials in C# but none of them work for me ex- site.
I would appreciate if anyone assist me in creating the tests or send me a site with tutorial in C#
My err from executed TC in VS-GoogleSearctTestErr.
I have one hub on a win10 machine, 2 nodes localy and 3rd node started on a VM Win 8.1 Grid console preview too-GridConsole
Thank you very much.
I will add my code here:
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Remote;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit;
using NUnit.Framework;
namespace TestOfGrid
{
[TestFixture]
public class Driver
{
IWebDriver driver;
[SetUp]
public void Setup()
{
// Create a new instance of the Firefox driver
driver = new FirefoxDriver();
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities = DesiredCapabilities.Firefox();
capabilities.SetCapability(CapabilityType.BrowserName, "firefox");
capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows));
driver = new RemoteWebDriver(new Uri("http://192.168.56.1:4444/wd/hub"), capabilities);
}
[TearDown]
public void Teardown()
{
driver.Quit();
}
[Test]
public void GoogleSearch()
{
string homepage = "http://www.google.co.uk";
//Navigate to the site
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
driver.Navigate().GoToUrl(homepage);
}
}
}
This test should be run in 3 browsers parallely. If I comment desired capabilities, the site is successfully opened, but I want to start my test on a separate browsers parallely.
I'm learning Selenium from the scratch and trying to run a test case on Firefox 50.0.1 using geckodriver I installed in VS2015 by selecting Selenium.WebDriver.GeckoDriver.Win64
However, when running the test I got an exception
Cannot start the driver service on localhost
What am I missing?
I was following some tutorials and performed step by step walk-through.
This is my code:
[TestMethod]
public void WebDriverSample()
{
IWebDriver webDriver;
//IWebDriver webDriver = new InternetExplorerDriver();
//Thread.Sleep(1000);
//webDriver.Dispose();
//webDriver = new ChromeDriver();
//Thread.Sleep(1000);
//webDriver.Dispose();
webDriver = new FirefoxDriver();
Thread.Sleep(1000);
webDriver.Dispose();
}
When using Firefox 47.0.2, I did not need to use geckodriver at all and it worked just fine.
Now, since browsers are getting updated, at some point I need to start using new versions. So, I need to find out what to do in order to be able to adapt to new changes and use geckodriver
Any suggestons?
I'm new to Appium but I have experience with selenium.
I need to write tests for a web view app.
But when I need to find an element I need to use the UIAutomatorViewer and use it like it's a native app.
Is there a way to use the DOM to navigate like when I'm working with the Chrome browser?
I tried this:
AppiumDriver<IWebElement> driver;
DesiredCapabilities cap = new DesiredCapabilities();
cap.SetCapability("deviceName", "LG - SERVER SERVER's Orange - G3");
cap.SetCapability("apppackage", "com.essence.adlfamily");
driver = new AndroidDriver<IWebElement>(new Uri("http://127.0.0.1:4723/wd/hub"), cap);