I am trying to use Coded UI compiled Dlls in Selenium project.
I Created on Class Library Project in Visual Studio where I created on class in this i write one simple method to draw highlight the "Save as window" like:
namespace CreadeDll
{
public class Class1
{
public void ValidateSaveasWidnow()
{
WinWindow window = new WinWindow();
window.SearchProperties.Add(WinWindow.PropertyNames.ControlType, "Window");
window.SearchProperties.Add(WinWindow.PropertyNames.Name, "Save Print Output As");
window.DrawHighlight();
}
}
}
After Build the application, i added this DLL in my selenium (C#, which is different project) project through reference.
namespace SeleniumProj
{
[TestFixture]
public class TestDll
{
[Test]
public void gets()
{
CreadeDll.Class1 c = new CreadeDll.Class1();
c.ValidateSaveasWidnow();
}
}
}
But the problem here is i am unable to Build. When i try to run it is giving message like "There were build errors"
Coded UI is available only in enterprise license of Visual Studio. Also VS 2019 will be the last version of Visual Studio that contains the Coded UI test functionality as Microsoft is deprecating the coded UI from later version onward. For more detail on this please follow this link .
I would suggest to go for appium Winappdriver to solve your windows UI control problem.
You can get appium winappdiver from this link : https://github.com/Microsoft/WinAppDriver
To learn more about WInappdriver you can refer the below links:
Winappdriver 8 minutes overview with demos
C# demo with calculator sample walkthrough
Related
I'm working with the ABP Framework and I'm implementing my own mail templates.
The project was made using the abp project template. I created the template in my Application module: Acme.Bookstore.Application/Assets/Templates/MyEmailTemplate.tpl. I edited the properties of the file to be embedded.
Then I made an instance of the template definition provider as follows:
public class MyEmailTemplateDefinitionProvider : TemplateDefinitionProvider
{
public override void Define(ITemplateDefinitionContext context)
{
context.Add(
new TemplateDefinition(
MyEmailTemplates.MyEmailTemplate,
displayName: LocalizableString.Create<AccountResource>($"TextTemplate:{MyEmailTemplates.MyEmailTemplate}"),
layout: StandardEmailTemplates.Layout,
localizationResource: typeof(AccountResource)
).WithVirtualFilePath($"Assets/Templates/MyEmailTemplate.tpl", true)
);
}
}
Then I added the following lines to my BookstoreApplicationModule.cs
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<BookstoreApplicationModule>("Acme.Bookstore");
});
I did all this following this documentation: https://docs.abp.io/en/abp/5.3/Virtual-File-System
When debugging locally all works well, but when I deploy the project it can't access the template file. The error is as follows:
Volo.Abp.AbpException: Could not find a file/folder at the location: Assets/Templates/MyEmailTemplate.tpl
I already tried adding the AddEbedded call in the HttpApi.Host module but got the same result. I don't know what I'm missing.
For the record, I'm deploying in an Ubuntu server, but that shouldn't matter.
The problem was that the embedded files weren't being added to the VirtualFileSystem. It worked in develpment because the framework calls:
if (hostingEnvironment.IsDevelopment())
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
... Some code ...
options.FileSets.ReplaceEmbeddedByPhysical<BookstoreApplicationModule>(
Path.Combine(hostingEnvironment.ContentRootPath,
$"..{Path.DirectorySeparatorChar}Acme.Bookstore.Application"));
});
}
So the problem didn't arise until I did a dotnet publish.
I could not figure out why it wasn't working on the Application module but moving the files to the Domain.Shared module fixed it.
I guess that there is some package or setting missing on the other module but this solution is enough for me.
I right click on my feature file I should get the option to Generate step definitions. It is not there in the context menu.
I did a search and it says to install specrun for nunit.
I tried installing SpecRun.Nunit from Manage NuGet Packages.
I get the error:
Severity Code Description Project File Line Suppression State
Error Unable to load the service index for source
http://packagesource.
An error occurred while sending the request.
The remote name could not be resolved: 'packagesource' 0
I have Visual Studio Enterprise 2017 isntalled.
I have installed Selenium-webdriver, Specflow
How can I solve this issue please, thanks.
You need to install the specflow nuget package as well as the Visual Studio integration package from the menu item Tools -> "Extensions and Updates..."
Here's what I have to do to make the option appear in the context menu in VS2019.
I installed Specflow normally, from Extensions-> Manage Extensions,
then searched for Specflow for Visual Studio 2019.
Installed the package and re-started VS.
Then I created a new project, a C# Test.
Once the initial setup is ready, from the context menu in the
Solution Explorer I went "Add->New Item..." and selected "SpecFlow
Feature File", I typed in the info I wanted in my Feature file.
Over any of the Gherkin lines, I right clicked to get the context
menu and selected "Go to Definition". A dialog displays, telling me
that there is not a match, but I can save the lines in clipboard. I
selected Yes.
Then again on the Solution Explorer (like step 4), Right Click
"Add->New Item...", but now selected "SpecFlow Step Definition". The
Step Definition will be that for the calculator test.
Now here's the trick:
Delete all of the steps, leaving the main class empty.
Like this:
using System;
using TechTalk.SpecFlow;
namespace SpecflowFirst
{
[Binding]
public class SpecFlowFeature1Steps
{
}
}
Then paste the snippet you got from the dialog box inside the main
class
Like this:
using System;
using TechTalk.SpecFlow;
namespace SpecflowFirst
{
[Binding]
public class SpecFlowFeature1Steps
{
[Given(#"I navigated to the github login page")]
public void GivenINavigatedToTheGithubLoginPage()
{
ScenarioContext.Current.Pending();
}
}
}
This will trigger errors in the compilation. If you point to the error in "ScenarioContext" and do "Show potential fixes", one of the fixes will be to install "Sprecflow extension". With this you install the remaining integration that will now display the option in the context menu.
That fixed the issue to me and now I can see in the context menu "Generate Step Definitions"
I followed Kyon's excellent walkthrough, but this didn't work for me. Even though SpecFlow was installed correctly, it didn't recognise the following library, or make any suggestions to "Fix this issue":
using TechTalk.Specflow
Then I noticed that, with the a brand-new MsTest project and the latest VS2019 (as of October 2020) you need to install a slightly-earlier version of SpecFlow (v2.1 compared to v2.4).
So, if you're also having problems getting this illusive "Generate Step Definitions" menu item to appear, check out your Dependencies\Packages for any exclamation marks.
I made a set of tests of IU with Selenium, creating for it a Class Library, when integrating it with VSTS, what should I do so that the tests run when I build it?
If it is the .net test project, you can refer to this article: Get started with Selenium testing in a CI pipeline
Simple steps:
Create a Unit Test project
Add Selenium.WebDriver, Selenium.WebDriver.ChromeDriver, Selenium.WebDriver.IEDriver, Selenium.Firefox.WebDriver, Selenium.WebDriver.PhantomJS.Xplatform packages to your project
Coding
Sample:
namespace Partsunlimited.UITests
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.PhantomJS;
using System;
[TestClass]
public class ChucksClass1
{
private string baseURL = "http://your-website.azurewebsites.net/";
private RemoteWebDriver driver;
private string browser;
public TestContext TestContext { get; set; }
[TestMethod]
[TestCategory("Selenium")]
[Priority(1)]
[Owner("FireFox")]
public void TireSearch_Any()
{
driver = new FirefoxDriver();
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
driver.Navigate().GoToUrl(this.baseURL);
driver.FindElementById("search - box").Clear();
driver.FindElementById("search - box").SendKeys("tire");
//do other Selenium things here!
}
[TestCleanup()]
public void MyTestCleanup()
{
driver.Quit();
}
[TestInitialize()]
public void MyTestInitialize()
{
}
}
}
Create new build definition
Add NuGet task to restore packages
Add Visual Studio Build task to build projects
Add Visual Studio Test Agent Deployment task to deploy test agent
Add Windows Machine File Copy to copy files to agent machine
Add Run Functional Tests task to run test
You also can use Visual Studio Test task to run test (Replace step 6 ~9), a blog: Running Selenium Tests as part of your release with VSTS Release Management
Here's my solution architecture:
VM (class lib) => references SQLite.
App (WPF Desktop App) => references VM.
VSIX (Visual Studio extension) => references VM.
I have copied EF providers related stuff from app.config of VM project to both desktop app and VSIX projects. The desktop app works fine whereas the VSIX project throws the following exception:
No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SQLite.EF6'. Make sure the provider is registered in the 'entityFramework' section of the application config file.
Is there something special I need to do in case of extension projects?
Adding the last line in the following class fixed it for me:
public class SQLiteConfiguration : DbConfiguration
{
public SQLiteConfiguration()
{
SetProviderFactory("System.Data.SQLite", SQLiteFactory.Instance);
SetProviderFactory("System.Data.SQLite.EF6", SQLiteProviderFactory.Instance);
SetProviderServices("System.Data.SQLite", (DbProviderServices)SQLiteProviderFactory.Instance.GetService(typeof(DbProviderServices)));
SetProviderServices("System.Data.SQLite.EF6", (DbProviderServices)SQLiteProviderFactory.Instance.GetService(typeof(DbProviderServices)));
}
}
Not sure why this exception was only being thrown in VSIX project, and not the desktop app.
Might help someone down the road.
I've been reading in the Allure wiki however I do not seem to be able to get started with Allure.
I have an IntelliJ project which I use to run JUnit tests with Selenium. I want to add Allure for better feedback after test runs. However I've not been able to understand how Allure would integrate with the rest of my project.
On the wiki page for JUnit it looks like Allure with JUnit only supports maven projects? How can I set up allure to work with an IntelliJ project?
I want to add Allure for better feedback after test runs
It is strange that you don't have a build tool.
But for single test (as you mention) following will work.
Dependencies - you need aither allure-junit-adaptor or allure-testng-adaptor
Allure implements test listener, which should be added to test runner:
For TestNG it happens automatically (once you add adaptor dependency).
For JUnit you should add listener manually. I don't know how to add it to Intellij Idea JUnit runner, but you can always run tests programmatically:
public static void main(String[] args) {
JUnitCore runner = new JUnitCore();
runner.addListener(new AllureRunListener());
runner.run(CalculatorTest.class);
}
That will generate XML report in target/allure-results folder.
If you need advanced Allure features like file attachments and test steps you need another dependency (aspectjweaver) and according JVM args, e.g.
-javaagent:lib/aspectjweaver-1.8.7.jar
To generate HTML report from existing XML report you can:
either use Allure CLI (requires tool installation http://wiki.qatools.ru/display/AL/Allure+Commandline)
or use 'mvn site' on existing project (e.g. https://github.com/allure-examples/allure-junit-example)
Open your HTML report in Firefox (or look here how to open locally generated report in Chrome).
To have allure-results after launching JUnit4 tests from IDE using context menu or controls on the gutter I use #RunWith anntotation where I set my custom runner with AllureJUnit4 listener.
CustomRunner class
package ru.atconsulting.qa.system.junit4runners;
import io.qameta.allure.junit4.AllureJunit4;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;
public class CustomRunner extends BlockJUnit4ClassRunner {
/**
* Creates a BlockJUnit4ClassRunner to run {#code klass}
*
* #param klass
* #throws InitializationError if the test class is malformed.
*/
public CustomRunner(Class<?> klass) throws InitializationError {
super(klass);
}
#Override
public void run(RunNotifier notifier) {
notifier.addListener(new AllureJunit4()); //just add listener
super.run(notifier);
}
}
Using #RunWith annotation in test classes
#RunWith(CustomRunner.class)
public class ExampleSuite {
#Test
public void testExample() {
....
}
}