Integrate test Selenium with VSTS - selenium-webdriver

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

Related

ABP Framework can't acces virtual files in Deploy

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.

Coded UI compiled DLLs in Selenium?

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

Ambiguous method call in appium WebDriver findElement API

I am using appium 6.1.0 which has <T extends WebElement> T findElement(By by); method on WebDriver class. Somewhere in automated tests I have following APIs -
protected String getText(WebElement element) {
return getText(element, Config.LOAD_WAIT);
}
and
protected String getText(By by) {
return getText(by, Config.LOAD_WAIT);
}
And getText method is invoked by test as -
public String getFullName() {
return getText(driver.findElement(By.cssSelector(".basicDataSection)))
}
But using WebDriver class from appium dependency throws exception on getFullName method about method call being ambiguous since it matches both getText(WebElement element) and getText(By by) How is this possible since findElement return type is T extends WebElement in WebDriver class in appium dependency?
On a different note, there is also WebElement findElement(By by); API in WebDriver class in selenium-api but after adding appium dependency method in my project they have begun to refer to WebDriver class from appium dependency and not from selenium-api dependency. Unfortunately WebDriver api in both classes have same package org.openqa.selenium.
I am not sure if WebDriver class from appium and selenium-api can be used interchangeably as they have different automation purpose (i.e. mobile app and web app). If WebDriver class from appium and selenium-api can not be used interchangeably then is there a way to enforce to use WebDriver class from selenium-api dependency and not from appium dependency?
Consider using MobileElement instead of WebElement to avoid clashes with underlying Selenium API
Make sure to have only appium-java-client library in your project dependencies, Appium 6.1.0 assumes Selenium 3.12.0 so you have to use exactly this version of Selenium in order to avoid Jar Hell so I would recommend using dependency management solution like Maven or Gradle to automatically resolve Appium Java client library and all its transitive dependencies. See Code Examples -> Appium with Java for comprehensive information and sample projects

How to export a TestNG suite to jar file

I'm new to Selenium I have exported TestNG suite to jar file using the Eclipse export option but am unable to run it.
Inorder to run a jar file you need to have a class with main method pointed to your Launch configuration while exporting.
you can run TestNG programmatically by creating this main method,
public static void main(String[] args) {
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { Run2.class });
testng.addListener(tla);
testng.run();
}
Add this main method class to your Launch Configuration while exporting the jar in eclipse.
Refer this testNG doc for more information : Run testNG programmatically
If you are using maven-jar-plugin to export jar make sure you have added your mainClass in manifest.

How do I set up Allure with JUnit in an IntelliJ project?

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() {
....
}
}

Resources