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.
Related
MS will stop supporting IE from June 2022, we are trying to find out a workaround to use Edge IE mode to do health checks we have for our IE supported applications. However, I can't see any supporting documents which show how to use Edge IE mode in Selenium Grid.
You can refer to the steps below to use Edge IE mode in Selenium Grid:
Download selenium-server-4.1.2.jar and IE Driver Server from here.
Download the corresponding version of Edge WebDriver from here (the same version as your Edge browser).
Put the paths of IE Driver Server and Edge WebDriver in Environment PATH.
Using the command prompt, navigate to the path of selenium server, then type on the command prompt to launch a hub:
java -jar selenium-server-4.1.2.jar hub
Using the command prompt, navigate to the same path and type on the command prompt to launch a node:
java -jar selenium-server-4.1.2.jar node
By default, the server will be listening on http://localhost:4444, and that’s the URL you should point your RemoteWebDriver tests.
Use the C# code below to run the automation test. The site will be opened in IE mode:
using System;
using System.IO;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Remote;
using System.Threading;
namespace WebDriverTest
{
class seleniumgrid
{
static void Main(string[] args)
{
var dir = #"E:\webdriver_path";
var driver = "IEDriverServer.exe";
if (!Directory.Exists(dir) || !File.Exists(Path.Combine(dir, driver)))
{
Console.WriteLine("Failed to find {0} in {1} folder.", dir, driver);
return;
}
var ieOptions = new InternetExplorerOptions { };
ieOptions.AttachToEdgeChrome = true;
ieOptions.EdgeExecutablePath = #"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
WebDriver webdriver = new RemoteWebDriver(new Uri("http://localhost:4444"), ieOptions);
webdriver.Navigate().GoToUrl("https://www.google.com");
Thread.Sleep(3000);
webdriver.Close();
webdriver.Quit();
}
}
}
Note: Please change the paths and URLs to your owns.
Reference link: Getting started with Selenium Grid
I want to click on the app menu button on the android emulator device.andoid emulator home screen
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium;
namespace AppTesting
{
[TestClass]
public class UnitTest1
{
AndroidDriver<AndroidElement> driver;
[TestMethod]
public void Scroll_Method()
{
DesiredCapabilities cap = new DesiredCapabilities();
cap.SetCapability("deviceName", "TestingMachine");
cap.SetCapability("platformversion", "7.0");
cap.SetCapability("platformName", "Android");
driver = new AndroidDriver<AndroidElement>(new Uri("http://127.0.0.1:4723/wd/hub"), cap);
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
driver.PressKeyCode(AndroidKeyCode.Keycode_MENU);
}
}
}
but when I run the code I get the following error
Message: Test method AppTesting.UnitTest1.Scroll_Method threw
exception: System.InvalidOperationException: An unknown server-side
error occurred while processing the command. Original error: The
desired capabilities must include either an app, appPackage or
browserName
I am new to mobile automation testing, what I don't understand at this point is why I need to provide an app-package and app-activity even when I am clicking on the button that is present on the home screen. If it is necessary to provide than what is the "app-package" and "app activity" for clicking the menu button.
Note:
Also, help on how to scroll through the android native application menu. Thanks in advance. Solution to this single problem will be an answer to many other problems that I am facing right now. I am new to mobile automation testing using Appium with C# in visual studio 2017
As a newbie you can try Appium Studio.
They have the object spy feature which would be easier for you to identify the elements.
And its possible to swipe the screen without providing the app-activity.
client.swipe(swipeDirection,offset,timeToSwipe);
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 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.
I am working with VS C# to manipulate test cases, create projects, and anything else that's beneficial to my testing in TFS. However, there are not any solid examples out there. The API that is on the Microsoft Developer site is just not helpful to me (could be my lack of experience in coding in VS), but I am becoming frustrated. Any progress that I make takes several days ( ... really hit and miss). Can someone direct me to a consolidated resource for using the team foundation server object model to implement features programmatically: WebSites, Books, etc...? Thanks!!! Below is what appears to be very straightforward code to create a Default collection/Project and write a test case in VSO TFS with C# (It continues to fail):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
namespace myProject
{
class Program
{
static void Main(string[] args)
{
string serverurl = "http://localhost:8080/tfs";
string project = "Beta1";
ITestManagementTeamProject proj = GetProject(serverurl, project);
ITestCase tc = proj.TestCases.Create();
tc.Title = "Test";
tc.Save();
Console.WriteLine("TC: {0}", tc.Id);
}
static ITestManagementTeamProject GetProject(string serverUrl,
string project)
{
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullQualifiedUriForName(serverUrl));
ITestManagementService tms = tfs.GetService<ITestManagementService>();
return tms.GetTeamProject(project);
}
}
}
The serverul "http://localhost:8080/tfs" in your code snippet means you are handling with on-premise TFS. But in your description, you want to create a test case work item in Visual Studio Online.
For Visual Studio Online api, you can refer to Visual Studio Online REST API at website:
https://www.visualstudio.com/en-us/integrate/api/overview
For deal with on-premise TFS programmatically, you can refer to blogs below:
http://joymonscode.blogspot.in/2009/05/beginning-tfs-programming.html
http://geekswithblogs.net/TarunArora/archive/2011/06/18/tfs-2010-sdk-connecting-to-tfs-2010-programmaticallyndashpart-1.aspx