Retry attribute is not working as expected - NUnit Framework - frameworks

We are using C# Selenium and NUnit framework for our test automation. Sometimes some test cases will fail in dev environment during execution due environmental issues. I was trying to re-run the failed ones, by using Retry attribute. But it didn't work ( I have kept assertion failures as well)
Could you please have a look the below code
[TestFixture]
public class UITests : BaseClassProtractor
{
[SetUp]
public void Setup()
{
//**Call chrome driver and open app url set up**//
}
[Test]
[Retry(1)]
public TestMethod1()
{
//** Write test Steps
}
[TearDown]
public void TearDown()
{
Drivers.TryRemove(TestContext.CurrentContext.Test.FullName, out var localDriver);
localDriver?.Quit();
}
}
Thanks,
Khaja Shaik.

[Retry(1)] indicates that the test should only be run once! That is, it won't be retried if it fails. Use [Retry(2)] as a minimum.
If you continue to get failures, we need to see the exact failure message.

Related

After Deploying, ASP.NET application showing Internal server error

I deployed my ASP.NET application to a remote server with a hosting company, and when i try to send data from Postman, i get the internal server error with no definite error message. I have set custom error mode to off in the web config file. please can anyone help me? I have checked for several solutions but nothing.
PS: i am new to ASP.NET deployment with other companies apart from Azure
In this case, you should log error to file to see what issues in deployment mode.
This way i implemented global error log.
public class ExceptionHandlingAttribute : ExceptionFilterAttribute
{
public override void OnException(HttpActionExecutedContext context)
{
//Log Critical errors
// You can use log4net library and configure log folder
}
}
In WebApiConfig.cs file you register it.
public static void Register(HttpConfiguration config)
{
// .....
config.Filters.Add(new ExceptionHandlingAttribute());
}

NUnit tests all failed in Visual Studio Code (MacOS)

I just started using VSCode (MacOS) and no matter the assertion, it always failed but it's not throwing any errors or warning to indicate that I set it up wrong. I have the following test unit:
using NUnit.Framework;
public class SampleTests
{
[Test]
public void SimpleAssertion() {
Assert.That(true);
}
}
Console output:
Running test SampleTests.SimpleFail...
Test failed
How do I run NUnit inside VSCode properly?

Extbase: scheduler cannot load a class

I have a scheduler (extension "scheduler" 6.2.0) task class:
namespace MyVendor\MyExt\Scheduler;
class MultiStepProcessTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
public function execute() {
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$businessLogic = $objectManager->get(\MyVendor\MyExt\Scheduler\MultiStepProcessTaskBusinessLogic::class);
return $businessLogic->run();
}
}
And a class implementing business logic for the scheduler task:
namespace MyVendor\MyExt\Scheduler;
class MultiStepProcessTaskBusinessLogic {
public function run() {
...
}
}
I created a scheduler task in BE. If I run it manually - it's OK. If it is started automatically - following error message comes:
[scheduler]: Task failed to execute successfully. Class:
MyVendor\MyExt\Scheduler\MultiStepProcessTask, UID: 8. Could not
analyse class:
MyVendor\MyExt\Scheduler\MultiStepProcessTaskBusinessLogic maybe not
loaded or no autoloader? (msg#4.0.255)
The best is - after being once run manually, the task runs automatically without errors until the cache is cleared. After that it needs one manual run again.
One more strange thing: in the main scheduler task class (MultiStepProcessTask) no injection is possible. That's why I had to create business logic object via objectManager
The best solution would be to write a command controller based on extbase. There you can use the ObjectManager and you can run it directly from CLI and of course also call it via scheduler!

Has anyone successfully deployed a GWT app on Heroku?

Heroku recently began supporting Java apps. Looking through the docs, it seems to resemble the Java Servlet Standard. Does anyone know of an instance where a GWT app has been successfully deployed on Heroku? If so, are there any limitations?
Yes, I've got a successful deployment using the getting started with Java instructions here:
http://devcenter.heroku.com/articles/java
I use the Maven project with appassembler plugin approach but added gwt-maven-plugin to compile a GWT app during the build.
When you push to heroku you see the GWT compile process running, on one thread only so quite slow but it works fine.
The embedded Jetty instance is configured to serve up static resources at /static from src/main/resources/static and I copy the compiled GWT app to this location during the build and then reference the .nocache.js as normal.
What else do you want to know?
You've got a choice, either build the Javascript representation of your GWT app locally into your Maven project, commit it and the read it from your app, or to generate it inside Heroku via the gwt-maven-plugin as I mentioned.
The code to serve up files from a static location inside your jar via embedded Jetty is something like this inside a Guice ServletModule:
(See my other answer below for a simpler and less Guice-driven way to do this.)
protected void configureServlets() {
bind(DefaultServlet.class).in(Singleton.class);
Map<String, String> initParams = new HashMap<String, String>();
initParams.put("pathInfoOnly", "true");
initParams.put("resourceBase", staticResourceBase());
serve("/static/*").with(DefaultServlet.class, initParams);
}
private String staticResourceBase() {
try {
return WebServletModule.class.getResource("/static").toURI().toString();
}
catch (URISyntaxException e) {
e.printStackTrace();
return "couldn't resolve real path to static/";
}
}
There's a few other tricks to getting embedded Jetty working with guice-servlet, let me know if this isn't enough.
My first answer to this turned out to have problems when GWT tried to read its serialization policy. In the end I went for a simpler approach that was less Guice-based. I had to step through the Jetty code to understand why setBaseResource() was the way to go - it's not immediately obvious from the Javadoc.
Here's my server class - the one with the main() method that you point Heroku at via your app-assembler plugin as per the Heroku docs.
public class MyServer {
public static void main(String[] args) throws Exception {
if (args.length > 0) {
new MyServer().start(Integer.valueOf(args[0]));
}
else {
new MyServer().start(Integer.valueOf(System.getenv("PORT")));
}
}
public void start(int port) throws Exception {
Server server = new Server(port);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setBaseResource(createResourceForStatics());
context.setContextPath("/");
context.addEventListener(new AppConfig());
context.addFilter(GuiceFilter.class, "/*", null);
context.addServlet(DefaultServlet.class, "/");
server.setHandler(context);
server.start();
server.join();
}
private Resource createResourceForStatics() throws MalformedURLException, IOException {
String staticDir = getClass().getClassLoader().getResource("static/").toExternalForm();
Resource staticResource = Resource.newResource(staticDir);
return staticResource;
}
}
AppConfig.java is a GuiceServletContextListener.
You then put your static resources under src/main/resources/static/.
In theory, one should be able to run GWT using the embedded versions of Jetty or Tomcat, and bootstrap the server in main as described in the Heroku Java docs.

InteropServices.COMException when running WatiN tests

When I run WatiN tests on our build server they all throw this InteropServices.COMException:
MyTestClassName.MyTestMethodName:
System.Runtime.InteropServices.COMException : Creating an instance of the COM component with CLSID {0002DF01-0000-0000-C000-000000000046} from the IClassFactory failed due to the following error: 80004005.
I get the same result wether I run them through TeamCity or I run them manually on the server as an administrator using NUnit GUI (2.5).
This is some sample code:
[TestFixture]
public class MyTestClassName
{
private string pageUrl;
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
pageUrl = ConfigurationManager.AppSettings["SiteURL"] + "/Pages/MyPage.aspx";
Settings.MakeNewIeInstanceVisible = false;
}
[Test]
public void MyTestMethodName()
{
using (var ie = new IE(pageUrl))
{
ie.SelectList(new Regex(#"^*DropDownList1*$")).Option("TheOption").Select();
ie.SelectList(new Regex(#"^*DropDownList2*$")).Option("AnOption").Select();
ie.SelectList(new Regex(#"^*DropDownList3*$")).Option("OtherOption").Select();
}
}
}
Any ideas what it can be?
/Joakim
Try running Visual Studio as Administrator.
I also meet the same problem but more strange for me.
I've got a server only for "UI testing" and for many application de WatiN test runs without any problem.
This error only happens for one application and only in CruiseControl (with nant) but not when runing the test with NUnitGUI...
I Finnaly found a solution this morning: I replaced all my call new IE(); to new IE(true) WatiN release note And didn't get the error anymore.
Another fix is to "Enable Protected mode in IE" like described here
Every time IE.Quit was called by WatiN IE would stop responding and then try to recover. Run as admin fixed the problem for me.
Another comment says:
Try running Visual Studio as Administrator
It is actually NUnit that needs to be run as administrator (at least in Windows 7), but the thinking is correct.
I think that the select list is not yet fully loaded and ready, and this is another symptom of the same problem described in this question:
Access denied error ( Visual Studio and WatiN )