is it possible to archive the report of TestNG? - selenium-webdriver

How do I archive the results (report) of the tests in Selenium 2 (Webdriver) so as to be able to return to them? Each performance suite overwrites the previous report, as it can be prevented? I use a simple html report.

//FOR EXAMPLE YOU WANT TO TEST THIS CLASS AND WANT TO CREATE NEW OUTPUT FOLDER FOR EACH EXECUTION
public class TestClass {
#Test
public void testME(){
System.out.println("Success");
}
}
//Then create new class which will be the start point of your execution, and run it from here
public class MainClass {
//This code will be your start point of execution
#Test
public void testCode(){
Random randomNo = new Random();
TestListenerAdapter listener = new TestListenerAdapter();
TestNG testng = new TestNG();
//Here you are changing Output directory and archive it for further
//use, OUTPUT FOLDER WILL BE ADDED BY APPPENDING RANDOM NUMBER ON IT
testng.setOutputDirectory("test-output"+randomNo.nextInt());
//ADD ALL TEST CLASSES WHERE YOUR TESTNG CODE IS PRESENT WITH #Test
testng.setTestClasses(new Class[]{TestClass.class});
testng.addListener(listener);
testng.run();
}
}

Related

What's the purpose of creating another class "ExtentReports" here?

public class ExtentReportDemo {
#BeforeTest
public void config()
{
String path = System.getProperty("user.dir")+\\reports\index.html; //user.dir - it means project path in the system
ExtentSparkReporter reporter = new ExtentSparkReporter(path);
reporter.config().setReportName("Web Automation results");
reporter.config().setDocumentTitle("Test results");
ExtentReports extent =new ExtentReports();
extent.attachReporter(reporter);
}
Above code already has "ExtentSparkReporter" class in 4th line but what's the purpose of creating another class called "ExtentReports" here in last two lines?
ExtentReports extent =new ExtentReports();
extent.attachReporter(reporter);

Salesforce Apex Test Class for an auto convert apex class. REceiving errors moving to production

I have an apex class that works how I want it in the sandbox. Trying to move it to production and need to write a test class. Used an example provided but I continue to get errors when running test that the lead was already converted. Need Help!
#isTest
public class TestAutoConvertLeads{
static testMethod void createnewlead() {
User userToCreate = [Select id from user where profile.name='System Administrator' Limit 1];
Test.startTest();
Lead leadToCreate =new Lead();
List<id> Ids= New List<Id>();
leadToCreate.ownerid= userToCreate.id;
leadToCreate.LastName ='Gupta';
leadToCreate.LeadSource='Partner Referral';
leadToCreate.Rating='';
leadToCreate.Status='';
insert leadToCreate;
Ids.add(leadToCreate.id);
AutoConvertLeads.LeadAssign(Ids);
Test.stopTest();
}
}
Also adding original apex class:

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

Adding Allure #step annotation without specific method

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

MEF Recomposition error

I get the exception:
1) More than one export was found that matches the constraint:
ContractName CompositionTest.C
RequiredTypeIdentity CompositionTest.C
When running the program
namespace CompositionTest
{
// [Export] // Also doesn't work
[Export(typeof(C))]
public class C
{
//[ImportAttribute(AllowRecomposition = true)] // also doesn't work
[Import(AllowRecomposition = true)]
public C PropertyC { get; set; }
}
class Program
{
static void Main(string[] args)
{
// Declare a composition container.
CompositionContainer compositionContainer = new CompositionContainer();
compositionContainer.ComposeParts( new C() );
compositionContainer.ComposeParts( new C() ); // exception here!
}
}
}
What am I doing wrong?
The first time you call ComposeParts, a new C object is added as an export to the container. Then second time you call ComposeParts, another C object is added as an export. This creates a problem with the import because there are two possible parts for import and MEF cannot make a decision. Hence the cardinality exception.
One solution would be to change the import to:
[ImportMany(AllowRecomposition = true)]
public IEnumerable<C> PropertyC { get; set; }
Another solution is to actually use a catalog when creating the container. This is the common way to use MEF. Pretty much all the examples you can find follow this approach:
//Create a catalog. In this case, a catalog based on an already loaded assembly.
var catalog = new AssemblyCatalog(typeof(C).Assembly);
//Create a container using the catalog. Only the parts from that catalog will be used.
var compositionContainer = new CompositionContainer(catalog);
For more on catalogs you should read this article.
By the way I have never seen such an example of MEF usage before. My answer is mainly based on observations I made while debugging it.

Resources