Adding Allure #step annotation without specific method - allure

I would like to create Allure step for specific code line and not per method, is it possible?I know that there is an Allure class with some helper methods but I can't figure out how to create a step.

You can do this by creating a separate class with Step method and call it everytime you want to add step info. For example:
import ru.yandex.qatools.allure.annotations.Step;
public final class LogUtil {
private LogUtil() {
}
#Step("{0}")
public static void log(final String message){
//intentionally empty
}
}
Above class contains the method for creating a step in allure. Now whenever you want to add step info in a test all you need to do is call this method like below:
LogUtil.log("Step information text");
You can find the detailed explanation here

Related

PageInit does not work when on different class

As the title says I am using PageFactory to initialize my elements.
When I use PageFactory.initElements on the page I want to use my elements everything is fine and works correctly, but when I try to create a new class with PageFactory to have it initialize all elements there I get a null pointer exception.
Below you will find the code I am using:
Actions.java
TestIds testIds = new TestIds();
public void initElements(WebDriver driver) {
PageFactory.initElements(driver, cashierIds);
}
The above lines work when included in my Actions class but when I create a new Class called ElementInitialization.java, move everything in it and then call it my elements throw nullPointerException.
Is there a different way to call the specific faction to work everywhere?

Retrieve executionId inside CommandInterceptor

I am implementing my own Activiti command intereceptor like this :
public class ActivitiCommandInterceptor extends AbstractCommandInterceptor {
private RuntimeService runtimeService;
private CommandInterceptor delegate;
public ActivitiSpringTxCommandInterceptor(RuntimeService runtimeService, CommandInterceptor delegate) {
this.runtimeService = runtimeService;
this.delegate=delegate;
}
#Override
public <T> T execute(CommandConfig config, Command<T> command) {
String myVariable = runtimeService.getVariable(<missingExecutionId>, "myVariableName");
...
}
}
Inside the execute() method I need to retrieve a variable from the execution context related to this command.
To do that, I need to have the executionId, but I can't find a way to retrieve it.
How can I get my variable from this interceptor?
Thanks
You can create a nativeExecutionQuery
This allows us to use SQL to perform operations directly on DB.
For your case, just find all the execution IDs that contains your variables, and filter them according to your need.

Salesforce deploy Apex Class to production 0% code coverage

I am using Salesforce and I want to deploy a custom Apex Class from my sandbox. In production there is no Apex Classes and the estimated code coverage is 0% so when I try to deploy my class I get the following error
Is there a way to deploy my class ?
The Class I want to deploy is here:
Public class AutoConvertLeads
{
#InvocableMethod
public static void LeadAssign(List<Id> LeadIds)
{
List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
for(id currentlead: LeadIds){
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(currentlead);
Leadconvert.setConvertedStatus('Qualified');
MassLeadconvert.add(Leadconvert);
}
if (!MassLeadconvert.isEmpty()) {
List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
}
}
}
Test Class:
#isTest
Private class UnitTest_AutoConvert
{
Static TestMethod void AutoConvert()
{
// Create the Lead object
Lead testLead = new Lead(
FirstName='Demo 100800',
LastName = 'Demo 100800 UnitTest',
Status='Qualified',
company='Lacosta'
);
insert testLead;
test.StartTest();
List<Lead> lstOfLeadids = [ testLead.Id ]
AutoConvertLeads.LeadAssign(lstOfLeadIds)
test.stopTest();
}
}
In order to meet the production deployment requirements you must meet the testing requirements. At a basic level, this means that you must maintain 75% line coverage between your production code and your test classes. This is at the aggregate level - so you can have some Apex classes with more or less coverage, but it must be 75% of all of code. Additionally, all Apex triggers require at least 1 line of test coverage to pass testing.
Unfortunately, you have provided limited information in your question. It would be helpful if you could provide the code for your test class so we could determine why Salesforce is not executing your tests during deployment. My initial guess is that you have not decorated your test class correctly for Salesforce to know it is a test class.
If you want a friendly introduction to testing, try the testing Trailhead: https://trailhead.salesforce.com/en/content/learn/modules/apex_testing
Take a look at the documentation as Svatopluk recommended. Specifically make sure that following things are happening:
1) The test class is marked as "#isTest"
2) The test method within the class is marked as "#isTest" or "testMethod" in the declaration.
3) The test class actually instantiates and runs code within your target class.
4) Deploy the TargetClass and TestClass in the same change set - this is so Salesforce can actually execute the tests during deployment.
Here is an example block:
#isTest
public class TestTargetClass{
public static testMethod void TestExectuableMethod() {
Test.startTest();
TargetClass instance_tc = new TargetClass();
instance_tc.executable_method();
Test.stopTest();
System.assert(<some sort of test to confirm that your TargetClass operates correctly>);
}
}
EDIT BASED ON POSTED TEST CODE:
Your test code has a number of issues.
First, it doesn't compile so I am not sure how you were able to get a passed test.
Lets review the errors in the following block:
test.StartTest();
List<Lead> lstOfLeadids = [ testLead.Id ]
AutoConvertLeads.LeadAssign(lstOfLeadIds)
test.stopTest();
The second line lstOfLeadids is of Type List of Lead but you are trying to populated it with an Id rather than a Lead.
This needs to be a List of Id since AutoConvertLeads.LeadAssign takes a List of Ids as the parameter.
Your instantiation of the lstOfLeadids is also wrong.
You are missing two semicolons.
Please use the following code:
test.StartTest();
List<Id> lstOfLeadids = new List<Id>{ testLead.Id };
AutoConvertLeads.LeadAssign(lstOfLeadIds);
test.stopTest();
In your actual AutoConvertLeads class, you are setting the lead convesion status to "Qualified". This didn't work on my Sandbox, but maybe it will on yours. You should be querying for the MasterLabel on the LeadStatus object of an IsConverted record to get the correct value.
You need to write test class to your class to be able to move it to production.
You can find basic explanation here

NUnit: How can I set name of test depending on parametr in [TestFixture(typeof(param))]

I'm using NUnit + Webdriver + C#. Setup class has next stucture:
[TestFixture(typeof(InternetExplorerDriver))]
[TestFixture(typeof(ChromeDriver))]
public partial class SetupBase<TWebDriver> where TWebDriver : IWebDriver, new()
{
public IWebDriver _driver;
[OneTimeSetUp]
public void OneTimeSetUp()
{
Init();
}
}
How can I set name of tests to include methode name, arguments and name of browser?
I tried with capabilities but it didn't help
ChromeOptions options = new ChromeOptions();
options.AddAdditionalCapability("Name", String.Format ("{0}_Chrome", TestContext.CurrentContext.Test.Name), true);
Also tried to use next code but was not able to find way how to pass driver type to NameAttribute
public class NameAttribute : NUnitAttribute, IApplyToTest
{
public NameAttribute(string name)
{
Name = String.Format("{0} {1}", name);
}
public string Name { get; set; }
public void ApplyToTest(Test test)
{
test.Properties.Add("Name", Name);
}
}
Can you help me please. Maybe need to update base class structure somehow?
This is how I use in tests
public class _001_General<TWebDriver> : SetupBase<TWebDriver> where TWebDriver : IWebDriver, new()
{
[OneTimeSetUp]
public void OneTimeSetupTest ()
{
//somework
}
[Test]
public void Test ()
{
//somework
}
}
Also SetupBase class contains functions that are used in tests
In NUnit, test cases, test methods, test fixtures and generic test fixture classes are all "tests" even though we sometimes talk loosely about "tests" as meaning test cases.
In your example, the following names are created:
_001_General<TWebDriver> (or maybe _001_General<>)
_001_General<InternetExplorerDriver>
Test
_001_General<ChromeDriver>
Test
Tests also have "fullnames", similar to that for a type or method. For example
_001_General<ChromeDriver>.Test
(Note: the fullname would also include a namespace, which I haven't shown.)
If you are using a runner that displays fullnames, like the NUnit 3 Console Runner, then there is no problem. So, I assume you are not. :-)
Some runners, like the NUnit 3 Visual Studio Test Adapter use simple test case names. So you would end up with a bunch of tests displayed with the name "Test."
Is that your problem? If so, this is not much of an answer. :-) However, I'll leave it as partial and add to it after hearing what runner you want to use and what you would like to see displayed in it.
UPDATE:
Based on your comment, what you really want to see is the test FullName - just as it is displayed by the NUnit 3 Console runner that TC runs for you. You'd like to see them in the VS IDE using the NUnit 3 VS Adapter.
Unfortunately, you can't right now. :-) More on that below. Meanwhile, here are some workarounds:
Use the console runner on your desktop. It's not as visual but works quite well. It's how I frequently work. Steps:
Install the console runner. I recommend using Chocolatey to install it globally, allowign you to use it with all your projects.
Set up your project to run the console runner with any options you like.
Make sure you use an external console window so you get the color display options that make the console runner easier to use.
Size your windows so you can see everything (if you have enough screen space) or just let the console run pop up on top of VS.
Try to trick VS by setting the test name in a way that includes the driver parameters. That's what you are already doing and it sounds as if you have already gotten almost all you can out of this option, i.e. class name without class parameters. You could try to take it a step further by creating separate classes for each driver. This would multiply the number of classes you have, obviously, but doesn't have to duplicate the code. You could use inheritance from the generic classes to create a new class with only a header in each place where it's needed. Like...
public class TestXYZDriver : TestDriver ...
This might be a lot of work, so it really depends on how important it is to you to get visual results that include fixture parameters right now.
For the future, you could request that the NUnit 3 Adapter project give an option of listing tests by their full names. I haven't worked on that project for a few years, so I'm not sure if it's actually possible. It may not be entirely in the control of the adapter, since VS controls what is displayed.

Can mockito or easymock replace rmock

I'm sitting with a legacy project, and we're starting to replace some old legacycode. As Rmock don't have support for junit4, we would like to replace it. One thing i was wondering is - how could i replace the dynamictestsuite feature of rmock. This is a good feature where you create a dynamic testsuite for each run, and can do stuff like.
#Override
protected void setupSuite() {
forEach(is.clazz.assignableTo(TestCase.class).and(is.not(is.clazz.name(is.endingWith("oldTest")))).perform(addAllToSuite);
}
that would get all testclasses not ending with oldTest and create a dynamictestsuite. And so on, you get the point.
ClasspathSuite can define a suite by searching for JUnit test classes in the class path, with a filter on the test class names to include or exclude.
import org.junit.extensions.cpsuite.ClasspathSuite.*;
import org.junit.runner.RunWith;
#RunWith(ClasspathSuite.class)
#ClassnameFilters({"!.*oldTest"})
public class MySuite {}

Resources