I have a Selenium framework that has been smooth sailing ever since it's creation. I implemented the Visual Studio Team Explorer today and after pulling from my remote branch, Intellisense started yelling at me, saying that one of my namespaces does not exist. The lines that it doesn't like are
using PageObjectModel.PageObjects.Maintenance;
and
var SettlementAccountReconciliations = new SettlementAccountReconciliation(_driver);
The SettlementAccountReconciliation is found within the Maintenance directory. Here is my full code for the test class where it does not like the directory:
using NLog.Internal;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using PageObjectModel.ControlObjects;
using PageObjectModel.PageObjects;
using PageObjectModel.PageObjects.Process;
using PageObjectModel.PageObjects.Status;
using System;
using PageObjectModel.PageObjects.Maintenance; // **LINE WITH MAINTENANCE UNDERLINED**
namespace PageObjectModel.Tests.TaskTesting
{
[TestFixture]
class JiraTaskTesting
{
private IWebDriver _driver;
[OneTimeSetUp]
public void SetUp()
{
_driver = new ChromeDriver();
DriverContext.Driver = _driver;
_driver.Manage().Window.Maximize();
var ConfigManager = new ConfigurationManager();
var Login = new Login(_driver);
Login.SignIn(ConfigManager.AppSettings["Username"], ConfigManager.AppSettings["Password"]);
}
[Test]
public void ReportNameStandardizationSettlementAccountReconciliations()
{
// **LINE WITH UNDERLINE**
var SettlementAccountReconciliations = new SettlementAccountReconciliation(_driver);
var Utilities = new Utilities(_driver);
var ReportPopup = SettlementAccountReconciliations.ExportReconciliationReport();
ReportPopup.StartDate.SetValue(DateTime.Now.ToString("MM/dd/yyyy"));
ReportPopup.EndDate.SetValue(DateTime.Now.ToString("MM/dd/yyyy"));
ReportPopup.ExportButton.Click();
Assert.IsTrue(Utilities.ValidateFilePresent("Settlement Account Reconciliation"));
Utilities.DeleteFile("Settlement Account Reconciliation");
}
Also, here is the SettlementAccountReconciliation found within the Maintenance namespace:
using OpenQA.Selenium;
using OpenQA.Selenium.Support.PageObjects;
using OpenQA.Selenium.Support.UI;
using System;
namespace PageObjectModel.PageObjects.Maintenance
{
public class SettlementAccountReconciliation
{
private readonly IWebDriver _driver;
public SettlementAccountReconciliation(IWebDriver driver)
{
_driver = driver;
PageFactory.InitElements(driver, this);
var Utilities = new Utilities(driver);
string TradingUrl = Utilities.RefactorUrl("/SettlementAccountReconciliation");
driver.Navigate().GoToUrl(TradingUrl);
WebDriverWait Wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
try
{
Wait.Until(ExpectedConditions.ElementExists(By.XPath("//a[text()='Settlement Account Reconciliations']")));
Console.WriteLine("SettlementAccountReconciliation Page Label Found");
}
catch
{
Console.WriteLine("SettlementAccountReconciliation Page Label Not Found, timing out");
}
}
This is an image of what is shown in my test class for the Directives:
And for the SettlementAccountReconciliation constructor:
I have all of my code in the Page Object Model format, and this is how my file structure is lined out:
I know this question is long winded but to continue, the tests run just fine, and the solution builds like a charm. I just need to figure out how to get the text editor to not think there are issues with my code.
Visual Studio tells me that "The type or namespace name 'Maintenance' does not exist in the namespace PageObjectModel.PageObjects'", but it does.
Any help on this would be greatly appreciated.
EDIT:
I fixed it.
I don't why it worked, but it did.
All I did was renamed the Maintenance folder to Maintenance1, recreated the Maintenance folder, and dragged and dropped the SettlementAccountReconciliation class into the Maintenance folder.
I am guessing there was some random property or setting stored in a temp folder somewhere in Timbuktu that was stored for the existing folder that was reset or deleted when the new folder was created.
Thanks to everyone who put time into helping me out!
I've had this issue before myself. Check the file and folder names in your project directory, the namespaces and assembly name within the properties of your project, and check that, if you've added the project as a reference, that the path to the reference is consistent with the actual path. I have a strong feeling that there is some inconsistency somewhere if you've refactored this at any point and the code you think you are referencing isn't actually what is being referenced.
I renamed the Maintenance folder to Maintenance1, recreated the Maintenance folder, and dragged and dropped the SettlementAccountReconciliation class into the Maintenance folder, and it seems to have fixed the issue.
I am guessing there was some random property or setting stored in a temp folder somewhere in Timbuktu that was stored for the existing folder that was reset or deleted when the new folder was created.
Related
I am researching how to generate environments in Unity using GIS data in KML format. I came across the SharpKML plugin and it seems to be ideal for my needs.
However, I am experiencing a strange error in that Unity throws an error
“CS0246: The type or namespace name ‘SharpKml’ could not be found (are you missing a using directive or an assembly reference?)”
The reference is added to VS and I have using SharpKML.Dom and using SharpKML.Engine entries which compile in VS with no problems.
But Unity still throws the error.
I have installed via NuGet and have also downloaded the SharpKML source code and rebuilt the dll on my machine and referenced directly with no change. VS also seems to drop the reference intermittently.
Have you come across this problem before or have any idea what is causing it?
The version of Unity is 2019.1.4f1 and the the version of VS is 2017 running framework 4.7.03062
I have recreated the project on a different machine on a different network and experience the same problem.
using UnityEngine;
using System.IO;
using System.Linq;
using SharpKml.Dom;
using SharpKml.Engine;
public class RenderKML : MonoBehaviour
{
public string KLMPath;
// Start is called before the first frame update
void Start()
{
string kmlPth = "Assets\\kml";
GetKMLFiles(kmlPth);
}
private void GetKMLFiles(string pth)
{
if (pth != null)
{
DirectoryInfo dir = new DirectoryInfo(pth);
FileInfo[] info = dir.GetFiles("*.kml");
foreach (FileInfo f in info)
{
print(f.FullName);
GetKMLData(f);
}
}
}
private void GetKMLData(FileInfo fI)
{
// This will read a Kml file into memory.
Stream fs = new FileStream(fI.FullName, FileMode.Open);
KmlFile file = KmlFile.Load(fs);
Kml kml = file.Root as Kml;
if (kml != null)
{
foreach (var placemark in kml.Flatten().OfType<Placemark>())
{
print(placemark.Name);
}
}
}
}
Every time you press "Run", unity rewrites project files. You cant simply use nuget or add references from external projects. You should download all SharpKML dll files and put them in Assets folder manually. See this for more information: https://answers.unity.com/questions/458300/how-to-use-a-external-dll.html
You need to use the Plugin folder in Unity3D. Download your Package or DLL and put it there.
This link can be helpful
Been looking all day for a solution for this, with little to no luck. I have this Windows Forms app in C# - My goal is to branch a directory that is in my TFS repository, make changes to filenames/folder names within the newly created branch if possible, and check code back into TFS with updated folder name/filename structure.
Is there a package or a class that I'm not seeing that would allow me to create and manipulate branches, as well as checking in the code all from a c# winforms app? If so, an example would be much appreciated.
If you are using Client Object Model Reference to manage the Version Control programmatically.
To create a branch, you need to use the "CreateBranch()" method in Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer class.
Creates a branch on the server and checks it in without downloading
the branch to the client.
A sample for you reference:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.Client;
using System.Net;
namespace Model.versionControl
{
public static class CreateBranch
{
public static void CreateBranchWithComment()
{
NetworkCredential cre = new NetworkCredential("userName", "password", "domain");
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("http://TFSServerName:8080/tfs/CollectionName"), cre);
VersionControlServer vcServer = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
int changesetId = vcServer.CreateBranch(#"$/SourceControl/WebSites", "$/SourceControl/WebSites_Branch", VersionSpec.Latest);
new WorkspaceVersionSpec("machineName","domain\userName");
Changeset changeset = vcServer.GetChangeset(changesetId);
changeset.Update();
}
}
}
You could also take a look at this similar question: How to create a new source code branch using TFS API?
As for renaming a file or directory, you could use Workspace.PendRename Method, sample code please refer: How do I move a TFS file with c# API?
I was trying to write an analyser to get information about some methods using the roslyn syntax tree. The problem is: The analyser that I am writing, needs to be in the same solution as the solution that I want to analyse.
So, this is my code:
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
public static class Main
{
public static Solution solution { get; set; } = null;
public static string GetMethodInfo(string methodToFind)
{
Task<Solution> GetSolutionTask = null;
string namespaceToFind, classToFind, methodToFind, invocationToFind;
if (solution == null)
{
var workspace = Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create();
GetSolutionTask = workspace.OpenSolutionAsync(Config.SolutionPath);
}
if (GetSolutionTask != null) solution = GetSolutionTask.Result;
foreach (Project proj in solution.Projects)
{
Compilation compilation = proj.GetCompilationAsync().Result;
foreach (var tree in compilation.SyntaxTrees)
{
findMethodAndProcessIt()...
}
}
return String.Empty;
}
}
The problem I get is that no compilation has any syntax tree. I tried this same code by opening other solutions and it works. So clearly the problem here is to be trying to open the solution that the visual studio is using.
I have already tried to run this code with visual studio closed, only running the .exe , but the problem persists.
Do you have any idea on how to solve this?
You are using MSBuildWorkspace to open a solution. Typically, when use of MSBuildWorkspace leads to projects not being loaded correctly, no source files, etc, there has been a failure during msbuild processing. This usually happens when your application does not have the same binding redirects in its app.config file that msbuild uses (in msbuild.exe.config), which causes some custom tasks/extensions to fail to load due to versioning mismatch.
You'll want to copy the <assemblyBinding> section into your app.config.
I have a question about referencing exe files for multiple browser testing in selenium NUnit with C#. I have added the additional code to get my tests to run in each browser but each time I run the tests, I get the error : OpenQA.Selenium.DriverServiceNotFoundException. My question is, is there anyway to add the reference without specifically laying out a path? I don't think that I would be able to add a path to the current code I have, without refactoring what I have. Thanks for your help in advance.
Test Fixture
[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
[TestFixture(typeof(ChromeDriver))]
public class CustomerLogin<TWebDriver> where TWebDriver : IWebDriver, new()
{
private IWebDriver driver;
private string url;
[TestFixtureSetUp]
public void FixtureSetUp()
{
url = System.Configuration.ConfigurationManager.AppSettings["homeUrl"];
this.driver = new TWebDriver();
driver.Navigate().GoToUrl(url);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
}
Using statements
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
I believe you can set the path with something like this;
System.setProperty("webdriver.ie.driver", "C:\my\path\to\IEDriverServer.exe");
System.setProperty("webdriver.firefox.driber", "C:\my\path\to\FFDriver.exe");
Or, the better solution in my opinion is to add the drivers to your project and modify the build so that they end up in your drop folder. The code above is great for your local system but isn't portable. Most automation solutions are intended to 'work out of the box' which requires you to package your dependencies in the bin.
To package the drivers with your build; add a 'Drivers' folder to the project (right click the solution -> add -> new folder) then add the executables under there (right click the folder, add existing item). Now that you can see the driver exe in Solution Explorer right click and select properties, under Copy to Output Directory select 'Copy if Newer'.
After making some changed to the code I am able to run all tests on the big 3 browsers. I had to add the Chrome.exe and the IE.exe to the bin\Debug folder (The one with the WebDriver.dll's) Here are my changes to my code.
Test Fixtures
[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
[TestFixture(typeof(ChromeDriver))]
public class CustomerLogin<TWebDriver> where TWebDriver : IWebDriver, new()
{
private IWebDriver driver;
private string url;
[SetUp]
public void SetUp()
{
this.driver = new TWebDriver();
url = System.Configuration.ConfigurationManager.AppSettings["homeUrl"];
driver.Navigate().GoToUrl(url);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
//Finding the customer login link and clicking it
driver.FindElement(By.Id("Homepage_r2_c14")).Click();
}
[TearDown]
public void TearDown()
{
driver.Quit();
}
}
I'm working on Automation framework using WebDriver with C#. Its working fine with Firefox but not with IE.
I am getting the following error:
IEDriverServer.exe does not exist-The file c:\users\administrator\documents\visual studio 2010\projects\TestProject1\TestProject1\bin\Debug\IEDriverServer.exe does not exist. The driver can be downloaded at http://code.google.com/p/selenium/downloads/list
I am using IE 9 and Windows 7.
IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl("http://www.google.co.uk");
IWebElement queryBox = driver.FindElement(By.Name("q"));
queryBox.SendKeys("The Automated Tester");
queryBox.SendKeys(Keys.ArrowDown);
queryBox.Submit();
See also .
The IEDriverServer.exe (as well as ChromeDriver.exe) can be downloaded from:
http://selenium-release.storage.googleapis.com/index.html.
To get these to work with your Selenium tests, include the .exe in your test project, and set its properties to 'Copy Always'.
NOTE: You'll have to adjust the Add File dialog to display .exe files.
Doing this will resolve the error.
Here's a simple C# example of how to call the InternetExplorerDriver using the IEDriverServer.exe.
Refactor according to your needs.
Note: the use of driver.Quit() which ensures that the IEDriverServer.exe process is closed, after the test has finished.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.IE;
namespace SeleniumTest
{
[TestClass]
public class IEDriverTest
{
private const string URL = "http://url";
private const string IE_DRIVER_PATH = #"C:\PathTo\IEDriverServer.exe";
[TestMethod]
public void Test()
{
var options = new InternetExplorerOptions()
{
InitialBrowserUrl = URL,
IntroduceInstabilityByIgnoringProtectedModeSettings = true
};
var driver = new InternetExplorerDriver(IE_DRIVER_PATH, options);
driver.Navigate();
driver.Close(); // closes browser
driver.Quit(); // closes IEDriverServer process
}
}
}
Per Jim Evans (who works on IEDriverServer)
The .NET bindings don't scan the %PATH% environment variable for the
executable. That means for the .NET bindings only, the
IEDriverServer.exe is expected to either be found in the same
directory as the .NET bindings assembly, or you must specify the
directory where it can be found in the constructor to the
InternetExplorerDriver class.
Failure to do one of these things (or to
set the UseInternalServer property in the InternetExplorerOptions
class) will cause the .NET IE driver implementation to throw an
exception. This is strictly by design, as we want people to begin
using the standalone IEDriverServer.exe, and the ability to use an
"internal" or "legacy" version of the server will be removed in a
future release.
https://groups.google.com/forum/?fromgroups#!topic/webdriver/EvTyEPYchxE
If you're working with Visual Studio and C# I've updated my NareshScaler nuget package to install IEDriverServer, ChromeDriver etc automatically, meaning you can get up and running quicker.
http://nuget.org/packages/NareshScaler
Code for WebDriver using java to run with IE. I believe this concept might be helpful for you using C#:
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
File file = new File("C:\\Program Files\\Internet Explorer\\iexplore.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
driver = new InternetExplorerDriver(capabilities);
If above code doesn't work use the following instead of "File file = new File("C:\Program Files\Internet Explorer\iexplore.exe");":
File file = new File("F:\\Ripon\\IEDriverServer_Win32_2.25.2\\IEDriverServer.exe");
[Note: The version of IEDriverServer and Windows (32 or 64 bit) may vary individual to individual]
Give path only till folder where Internetexplorer.exe is located.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using System.IO;
namespace Automation
{
class To_Run_IE
{
static void Main(string[] args)
{
//Keep Internetexplorer.exe in "D:\Automation\32\Internetexplorer.exe"
IWebDriver driver = new InternetExplorerDriver(#"D:\Automation\32\"); \\Give path till the exe folder
//IWebDriver driver = new Firefoxdriver()
driver.Navigate().GoToUrl("http://www.google.com/");
driver.Manage().Window.Maximize();
IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys("Cheese");
query.Submit();
System.Console.WriteLine("Page title is: " + driver.Title);
driver.Quit();
}
} }
public IWebDriver IEWebDriver()
{
var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
webDriver = new InternetExplorerDriver(ConfigurationSettings.AppSettings["IDEServerPath"].ToString(), options);//Path of ur IE WebDriver,Here I stored it in a AppConfig File
return webDriver;
}