public class PrintMethodNames {
@Test
public void f() {
Assert.fail();
}
@AfterMethod(alwaysRun = true)
public void afterMethod(Method method) {
System.out.println("Currently run method was " + method.getName());
}
}
Hi,
Today i Start with testNG.
I have two doubts
1)For testing purpose i need to get the name of the testcase which is being executed at runtime. In junt i have used TestName class.Is there any thing like that in testng?
And
2) I have seen some methods like onTestStart, onTestFail..But i haven't seen any onTestSuccess(like any method which i can override to get access for a particular testmethod runtime even if test get failed or success). Is there any method which i can use in testNG for this purpose?
Regards,
varghese
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Hi krishnan
Below one is a sample program
In DemoStart,
i have @BeforeTest for instantiating instance of driver.
public class ConnectPlusRegisterTest extends DemoStart {
@Test(groups = { "sanity" }, description = "Sample", invocationCount = 1, threadPoolSize = 1, alwaysRun = true, enabled=true)
public void f() {
System.out.println("data");
loginConnectApplication("abcd", "abcd");
System.out.println("reached1");
}
@Test(dependsOnMethods ={"f"}, description="Sample dependent")
public void g(){
webdriver.findElement(By.xpath("/html/body/div/div[4]/a[6]")).click();
System.out.println("reached2");
}
In demoStart
@AfterMethod - quiting
In above example g depends on f
So if i am executing g testcase,
First it will execute the f after completion of f, it will call the @AfterMethod There webdriver will get quits, so for the g testcase there won't be any webdriver instance.
My question, since both testcase are dependent(Logically one)
Is there any method available to call after the completion of both dependent.
I don't want a call after execution of f testcase; need only after the g.
I tried with Listener, after Invocation - Problem is it will call after each configuration methods and test method, even if i check the condition of isTest, the above problem with AfterMethod is still there in afterinvocation also.
Regards,
varghese
On Wednesday, March 6, 2013 7:18:18 AM UTC+5:30, Krishnan wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
Thanks & Regards
Krishnan Mahadevan
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users?hl=en.
For more options, visit http
For more options, visit http
My question, since both testcase are dependent(Logically one)
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Hi
Below is example of one way of doing it (If I understood you correctly). The example prints the following:
Class 'MyTest'; method; 'm1'; description: 'Sample'
Class 'MyTest'; method; 'm2'; description: 'Sample dependent'
***************m1
***************m1
package example;
import java.lang.reflect.Method;
import java.util.Arrays;
import org.testng.ITestContext;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class MyTest {
@BeforeTest
public void testName(ITestContext ctx) throws Exception {
Arrays.stream(ctx.getAllTestMethods()).forEach(testMethod -> {
Method m = testMethod.getConstructorOrMethod().getMethod();
String className = getClass().getSimpleName();
String methodName = m.getName();
String description = m.getAnnotation(Test.class).description();
String template = "Class '%s'; method; '%s'; description: '%s'";
System.out.println(String.format(template, className, methodName, description));
});
}
@Test(description = "Sample")
public void m1() throws Exception {
System.out.println("***************m1");
}
@Test(description="Sample dependent")
public void m2() throws Exception {
System.out.println("***************m1");
}
}
/Alex
From: testng...@googlegroups.com [mailto:testng...@googlegroups.com]
On Behalf Of ?Krishnan Mahadevan?
Sent: den 29 mars 2016 09:35
To: testng...@googlegroups.com
Subject: Re: [testng-users] How to get test method name at runtime in testng?
I don't think you can do this in @BeforeTest because, @BeforeTest runs much before your actual tests that are going to be executed.
You can try getting this information via a TestNG listener [ by implementing IInvokedListener ] and then binding the listener to your test classes [ This[rationaleemotions.wordpress.com] blog post of mine will help you get an overview of listeners ].
If that's not what you are after, then I guess I didn't quite understand your question. So you might have to elaborate it a bit more
Thanks & Regards
Krishnan Mahadevan
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/[wakened-cognition.blogspot.com]
My Technical Scribbings @ http://rationaleemotions.wordpress.com/[rationaleemotions.wordpress.com]
On Tue, Mar 29, 2016 at 9:49 AM, Eswar Reddy <kesw...@gmail.com> wrote:
Hi All,
my question is in below script i would like to print CLASS NAME & TEST annotation DESCRIPTION.....and it should be print in @BeforeTest...how????
i have @BeforeTest for instantiating instance of driver.
public class ConnectPlusRegisterTest extends DemoStart {
@Test(groups = { "sanity" }, description = "Sample", invocationCount = 1, threadPoolSize = 1, alwaysRun = true, enabled=true)
public void f() {
System.out.println("data");
loginConnectApplication("abcd", "abcd");
System.out.println("reached1");
}
@Test(dependsOnMethods ={"f"}, description="Sample dependent")
public void g(){
webdriver.findElement(By.xpath("/html/body/div/div[4]/a[6]")).click();
System.out.println("reached2");
}
In demoStart
@AfterMethod - quiting
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users[groups.google.com].
For more options, visit https://groups.google.com/d/optout[groups.google.com].
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
testng-users...@googlegroups.com.
To post to this group, send email to
testng...@googlegroups.com.
Visit this group at
https://groups.google.com/group/testng-users[groups.google.com].
For more options, visit
https://groups.google.com/d/optout[groups.google.com].