Can somebody give me simple example to override test name at run time ?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Can somebody give me simple example to override test name at run time ?

Ramshankar Behera
Here is my code looks:

package com.tesla.ztesting;
import org.testng.ITest;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
public class test implements ITest
{
String testName = "ddd";    
@Test
public void factoryTest1() {
}
@Override
public String getTestName() {
    return this.testName;
}
@AfterMethod
public void setTestName( String name ) {
    this.testName = name;
}   
}

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can somebody give me simple example to override test name at run time ?

Ramshankar Behera
Sorry in place of AfterMethod  I have user BeforeMethod.

On Monday, May 12, 2014 5:19:28 PM UTC+5:30, Sonu wrote:
Here is my code looks:

package com.tesla.ztesting;
import org.testng.ITest;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
public class test implements ITest
{
String testName = "ddd";    
@Test
public void factoryTest1() {
}
@Override
public String getTestName() {
    return this.testName;
}
@AfterMethod
public void setTestName( String name ) {
    this.testName = name;
}   
}

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can somebody give me simple example to override test name at run time ?

ajourney
In reply to this post by Ramshankar Behera
What is your expected output with this code?
When do you want to see the name of your test changed? 
if thats the case you woiuldn't want to have the setTestName called in the AfterMethod that would be after the test is over.
On Monday, May 12, 2014 7:49:28 AM UTC-4, Sonu wrote:
Here is my code looks:

package com.tesla.ztesting;
import org.testng.ITest;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
public class test implements ITest
{
String testName = "ddd";    
@Test
public void factoryTest1() {
}
@Override
public String getTestName() {
    return this.testName;
}
@AfterMethod
public void setTestName( String name ) {
    this.testName = name;
}   
}

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can somebody give me simple example to override test name at run time ?

djangofan
In reply to this post by Ramshankar Behera
Yes, I created a project that does that here:  http://djangofan.github.io/testng-custom-report-example/
-Jon

On Monday, May 12, 2014 4:49:28 AM UTC-7, Sonu wrote:
Here is my code looks:

package com.tesla.ztesting;
import org.testng.ITest;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
public class test implements ITest
{
String testName = "ddd";    
@Test
public void factoryTest1() {
}
@Override
public String getTestName() {
    return this.testName;
}
@AfterMethod
public void setTestName( String name ) {
    this.testName = name;
}   
}

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can somebody give me simple example to override test name at run time ?

Ramshankar Behera
In reply to this post by ajourney

After each test execution I want to change the method name for the reporting purpose. Can you please tell me the example?

On May 14, 2014 1:35 AM, "ajourney" <[hidden email]> wrote:
What is your expected output with this code?
When do you want to see the name of your test changed? 
if thats the case you woiuldn't want to have the setTestName called in the AfterMethod that would be after the test is over.
On Monday, May 12, 2014 7:49:28 AM UTC-4, Sonu wrote:
Here is my code looks:

package com.tesla.ztesting;
import org.testng.ITest;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
public class test implements ITest
{
String testName = "ddd";    
@Test
public void factoryTest1() {
}
@Override
public String getTestName() {
    return this.testName;
}
@AfterMethod
public void setTestName( String name ) {
    this.testName = name;
}   
}

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/dl_k6jMkgFU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can somebody give me simple example to override test name at run time ?

Ramshankar Behera
In reply to this post by djangofan
Hi Jon,

Thanks for your reply on my question.

I tried to implement your project but in the default report I don't see the change name. Please find the attachment.

Thanks,
Ram.


On Tue, May 13, 2014 at 9:09 PM, djangofan <[hidden email]> wrote:
Yes, I created a project that does that here:  http://djangofan.github.io/testng-custom-report-example/
-Jon


On Monday, May 12, 2014 4:49:28 AM UTC-7, Sonu wrote:
Here is my code looks:

package com.tesla.ztesting;
import org.testng.ITest;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
public class test implements ITest
{
String testName = "ddd";    
@Test
public void factoryTest1() {
}
@Override
public String getTestName() {
    return this.testName;
}
@AfterMethod
public void setTestName( String name ) {
    this.testName = name;
}   
}

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/dl_k6jMkgFU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

testNg.PNG (51K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Can somebody give me simple example to override test name at run time ?

djangofan
That is because it changes the name while the test is running and so the name change doesn't show up in the Eclipse integration.  You need to open the HTML report in the  target directory to see the changed name.    Since I created that project I think I know how to change the name displayed in the Eclipse integration but I haven't tried it yet.  Basically, in the @BeforeMethod, pass a Object[] that contains the test name and then apply the name change within that before method.  Haven't tried it yet, but wanted to let you know what I was thinking.
-Jon

On Tuesday, May 13, 2014 11:54:53 PM UTC-7, Sonu wrote:
Hi Jon,

Thanks for your reply on my question.

I tried to implement your project but in the default report I don't see the change name. Please find the attachment.

Thanks,
Ram.


On Tue, May 13, 2014 at 9:09 PM, djangofan <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="tllYdaM9FJcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">aust...@...> wrote:
Yes, I created a project that does that here:  <a href="http://djangofan.github.io/testng-custom-report-example/" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fdjangofan.github.io%2Ftestng-custom-report-example%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHMBn8LtKzA211rtJNymnVSCVGZ0A';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fdjangofan.github.io%2Ftestng-custom-report-example%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHMBn8LtKzA211rtJNymnVSCVGZ0A';return true;">http://djangofan.github.io/testng-custom-report-example/
-Jon


On Monday, May 12, 2014 4:49:28 AM UTC-7, Sonu wrote:
Here is my code looks:

package com.tesla.ztesting;
import org.testng.ITest;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
public class test implements ITest
{
String testName = "ddd";    
@Test
public void factoryTest1() {
}
@Override
public String getTestName() {
    return this.testName;
}
@AfterMethod
public void setTestName( String name ) {
    this.testName = name;
}   
}

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/testng-users/dl_k6jMkgFU/unsubscribe" target="_blank" onmousedown="this.href='https://groups.google.com/d/topic/testng-users/dl_k6jMkgFU/unsubscribe';return true;" onclick="this.href='https://groups.google.com/d/topic/testng-users/dl_k6jMkgFU/unsubscribe';return true;">https://groups.google.com/d/topic/testng-users/dl_k6jMkgFU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="tllYdaM9FJcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="tllYdaM9FJcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">testng...@....
Visit this group at <a href="http://groups.google.com/group/testng-users" target="_blank" onmousedown="this.href='http://groups.google.com/group/testng-users';return true;" onclick="this.href='http://groups.google.com/group/testng-users';return true;">http://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can somebody give me simple example to override test name at run time ?

djangofan
Just wanted to update everyone that my "custom report" example that I linked to on this thread works fine as long as you don't use a data provider.  When you get a data provider involved, then the class instance is shared between multiple runs and the TestNG report shows the same name for all runs of that test.   Still haven't solved that problem but hopefully I will someday.
-Jon

On Sunday, July 6, 2014 9:27:04 AM UTC-7, djangofan wrote:
That is because it changes the name while the test is running and so the name change doesn't show up in the Eclipse integration.  You need to open the HTML report in the  target directory to see the changed name.    Since I created that project I think I know how to change the name displayed in the Eclipse integration but I haven't tried it yet.  Basically, in the @BeforeMethod, pass a Object[] that contains the test name and then apply the name change within that before method.  Haven't tried it yet, but wanted to let you know what I was thinking.
-Jon

On Tuesday, May 13, 2014 11:54:53 PM UTC-7, Sonu wrote:
Hi Jon,

Thanks for your reply on my question.

I tried to implement your project but in the default report I don't see the change name. Please find the attachment.

Thanks,
Ram.


On Tue, May 13, 2014 at 9:09 PM, djangofan <[hidden email]> wrote:
Yes, I created a project that does that here:  <a href="http://djangofan.github.io/testng-custom-report-example/" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fdjangofan.github.io%2Ftestng-custom-report-example%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHMBn8LtKzA211rtJNymnVSCVGZ0A';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fdjangofan.github.io%2Ftestng-custom-report-example%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHMBn8LtKzA211rtJNymnVSCVGZ0A';return true;">http://djangofan.github.io/testng-custom-report-example/
-Jon


On Monday, May 12, 2014 4:49:28 AM UTC-7, Sonu wrote:
Here is my code looks:

package com.tesla.ztesting;
import org.testng.ITest;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
public class test implements ITest
{
String testName = "ddd";    
@Test
public void factoryTest1() {
}
@Override
public String getTestName() {
    return this.testName;
}
@AfterMethod
public void setTestName( String name ) {
    this.testName = name;
}   
}

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/testng-users/dl_k6jMkgFU/unsubscribe" target="_blank" onmousedown="this.href='https://groups.google.com/d/topic/testng-users/dl_k6jMkgFU/unsubscribe';return true;" onclick="this.href='https://groups.google.com/d/topic/testng-users/dl_k6jMkgFU/unsubscribe';return true;">https://groups.google.com/d/topic/testng-users/dl_k6jMkgFU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users...@googlegroups.com.
To post to this group, send email to [hidden email].
Visit this group at <a href="http://groups.google.com/group/testng-users" target="_blank" onmousedown="this.href='http://groups.google.com/group/testng-users';return true;" onclick="this.href='http://groups.google.com/group/testng-users';return true;">http://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.