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() {
....
}
}
Related
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
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
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.
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
I am working on a Jenkins plugin that needs to know information about the build steps that are about to run.
I need this information before the jobs actually run.
I was not able to find this info neither on AbstractBuild or BuildListener classes.
Ideally i will use this info inside BuildStepListener but i as i am writing the plugin can collect it on any extension point
#Extension
public class MyBuildStepListener extends BuildStepListener{
#Override
public void started(AbstractBuild build, BuildStep bs, BuildListener listener) {
listener.getLogger().println("Get all build steps here");
}
...
}
An AbstractBuild just provides information about the current build — you need to get information from the job that this build belongs to.
You can use AbstractBuild#getProject() to do so, and then use AbstractProject#getBuilders() to get the build steps.