Error when trying to run a codedUI test - visual-studio

I am getting this error despite setting the option "Set as startup project". My application is a web based (browser) application. I have tried all other options and it does not work. Please advise ?
Screenshot

Make sure to put 'CodedUI' and 'TestMethod' attributes in your test class and test methods, else you would get such error.
[CodedUITest]
public class CodedUITest1
{
[TestMethod]
public void CodedUITestMethod1()
{
BrowserWindow br = new BrowserWindow();
BrowserWindow.Launch("www.Google.com");
}
}

Related

How to redirect springboot error page to vaadin error UI?

I have an error page in vaadin UI. But sometimes we can write a wrong url and we see the springboot error page.
I want to show vaadin UI error page in this case. By the way, I have already have a rendered 404 page for springboot. But I don't want to show it.
This is my vaadin error UI. But this works into the application. (http://localhost:7001/MyApplication/#!error)
sometimes I write an invalid url like this: http://localhost:7001/MyApplication/blablablabla
in this case I want to redirect vaadin error page (http://localhost:7001/MyApplication/#!error) But the springboot redirects me to rendered 404 page.
It is possible?
#UIScope
#SpringView(name = ErrorView.VIEW_NAME)
public class ErrorView extends VerticalLayout implements View {
public static final String VIEW_NAME = "error";
private Label explanation;
public ErrorView() {
Label header = new Label("The view could not be found");
header.addStyleName(MaterialTheme.LABEL_H1);
addComponent(header);
addComponent(explanation = new Label());
}
#Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
explanation.setValue(String.format("You tried to navigate to a view ('%s') that does not exist.", event.getViewName()));
getUI().getNavigator().navigateTo(ErrorView.VIEW_NAME);
}
}
you can put 404/500 page under resources/error/ folder, Spring boot will redirect those page automatic when have error
I think SpringNavigator can solve your problem. While defining your Navigator, you can also define error View. See the example below
#SpringUI(path = "ui")
public class DemoUI extends com.vaadin.ui.UI {
#Override
protected void init(VaadinRequest vaadinRequest) {
SpringNavigator navigator = new SpringNavigator();
navigator.setErrorView(new ErrorView());
setNavigator(navigator);
}
}

Overriding RequestEventListenerAdapter methods on Spring Boot (Stormpath)

I've been trying to override Stormpath's RequestEventListenerAdapter methods to populate an account's Custom Data when the user logs in or creates an account.
I created a class that extends RequestEventListenerAdapter and am trying to override the on SuccessfulAuthenticationRequestEvent and the on LogoutRequestEvent to make some simple outputs to the console to test if they are working (A simple "Hello world!" for example). But when I do any of these actions on the application, none of these events are triggering. So I was wondering if anyone here could help me out, I'm not sure if the bean I'm supposed to declare is in the right place or if I'm missing some kind of configuration for the events to trigger. Thanks for any help and let me know if more information is needed.
This is my custom class:
import com.stormpath.sdk.servlet.authc.LogoutRequestEvent;
import com.stormpath.sdk.servlet.authc.SuccessfulAuthenticationRequestEvent;
import com.stormpath.sdk.servlet.event.RequestEventListenerAdapter;
public class CustomRequestEventListener extends RequestEventListenerAdapter {
#Override
public void on(SuccessfulAuthenticationRequestEvent e) {
System.out.println("Received successful authentication request event: {}\n" + e);
}
#Override
public void on(LogoutRequestEvent e) {
System.out.println("Received logout request event: {}\n" + e);
}
}
This is the bean that I'm not sure where to place:
#Bean
public RequestEventListener stormpathRequestEventListener() {
return new CustomRequestEventListener();
}
What you are doing looks exactly right. I have created a sample project demonstrating how to get things working. You could take a look at it (it is very simple) and compare it with what you have.
I also added instructions on how to get it running so you can see that it does indeed work.

Getting Java.Lang.NullPointerException when trying to open GPS Settings page using Xamarin

I am getting the following error when trying to open GPS settings page if GPS is not enabled (within Xamarin):
Unknown identifier: StartActivity
Unhandled Exception:
Java.Lang.NullPointerException:
Can somebody please guide where am I getting wrong?
This My Interface
namespace MyApp
{
public interface GpsSettings
{
void showGpsSettings();
}
}
This the Implementation
[assembly: Xamarin.Forms.Dependency(typeof(GpsSettingsImplementation))]
namespace MyApp.Droid
{
public class GpsSettingsImplementation : Activity, GpsSettings
{
public GpsSettingsImplementation()
{
}
public void showGpsSettings()
{
var intent = new Intent(Android.Provider.Settings.ActionLocationSourceSettings);
StartActivity(intent);
}
}
}
This is how I call my function on button click
DependencyService.Get<GpsSettings>().showGpsSettings();
An existing Activity instance has a bit of work that goes on behind
the scenes when it's constructed; activities started through the
intent system (all activities) will have a Context reference added to
them when they are instantiated. This context reference is used in the
call-chain of StartActivity.
So, the Java.Lang.NullPointerException seen after invoking
StartActivity on your Test activity instance is because the Context
inside that instance has never been set. By using the new operator to
create an activity instance you've circumvented the normal way
activities are instantiated, leaving your instance in an invalid
state!
ref: https://stackoverflow.com/a/31330999/5145530
The above error can be resolved in the following manner:
[assembly: Xamarin.Forms.Dependency(typeof(GpsSettingsImplementation))]
namespace MyApp.Droid
{
public class GpsSettingsImplementation : Activity, GpsSettings
{
public GpsSettingsImplementation()
{
}
public void showGpsSettings()
{
var intent = new Intent(Android.Provider.Settings.ActionLocationSourceSettings);
intent.SetFlags(ActivityFlags.NewTask);
Android.App.Application.Context.StartActivity(intent);
}
}
}

Web API Help Pages always empty

I've added Help pages Nuget package to create documentation for my Web API but it doesn't work for me, no API methods are shown.
I uncommented line :
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
I checked box XML documentation file and set path to App_Data/XmlDocument.xml
I don't use Glimpse as many solutions here write about it.
I even installed nuget package for help pages with authorization but it doesn't help
What is wrong with this? If I start empty project than it is working fine, but this API is too big to start all over again.
In case you are using OWIN as middleware (just like me), you may be initializing a new HttpConfiguration inside it´s startup method. The problem is that the HelpController and the HelpPageConfig are using GlobalConfiguration.Configuration, which seems to be wrong. What helped me:
Step 1: make the startup HttpConfiguration a static field
[assembly: OwinStartup(typeof(MyProject.API.Startup))]
namespace MyProject.API
{
public class Startup
{
//new
public static HttpConfiguration HttpCfg;
//
public void Configuration(IAppBuilder app)
{
HttpCfg = new HttpConfiguration();
WebApiConfig.Register(HttpCfg);
app.UseWebApi(HttpCfg);
AreaRegistration.RegisterAllAreas();
}
}
}
Step 2: go to HelpPageAreaRegistration and edit the RegisterArea method like this
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"HelpPage_Default",
"Help/{action}/{apiId}",
new { controller = "Help", action = "Index", apiId = UrlParameter.Optional });
//old
//HelpPageConfig.Register(GlobalConfiguration.Configuration);
//new
HelpPageConfig.Register(Startup.HttpCfg);
}
Step 3: go to HelpController and edit the standard constructor like this
//old
//public HelpController() : this(GlobalConfiguration.Configuration){ }
//new
public HelpController() : this(Startup.HttpCfg){ }
I hope this helps and isn't too late ;)

Trouble in Using Quartz with spring webapp - Not able to see errors on cosole

I am using quartz within a Spring MVC application.
I have a task class, all functionality and logic is written there. I have a separate quartz configuration file. I am just hitting a URL and in controller function initializing the quartz conf file. The job is running fine. The issue I am facing is:
In my task class, some code is running and from a point of time. I am not getting it to run and I am not able to see any error or exception. Here is the code for my task class. I am able to run the getValues() function on a timely basis with quartz. The problem is it's printing the value hi and nothing else. It's not going in if nor else and neither is showing any error or exception.
public class TeamUpdateImpl implements TeamUpdate {
// #Autowired
ReadXmlDao readXmlDao;
public void setReadXmlDao(ReadXmlDao readXmlDao) {
this.readXmlDao = readXmlDao;
}
public void getValues() {
System.out.print("Hi");
if (readXmlDao.getName().equals("Hema")) {
System.out.print("if cond");
} else {
System.out.print("else cond");
}
}
}
Please suggest a solution, some logging thing or something so that I could get at least errors on my console to fix them.
Thanks.
I guess readXmlDao or readXmlDao.getName() is null.
Try to print it.
System.out.print("readXmlDao = "+readXmlDao);
System.out.print("readXmlDao.getName() = "+readXmlDao.getName());
You will get npe on printing readXmlDao.getName() if readXmlDao is null.
Also
Try to set #Autowired on setReadXmlDao method.
#Autowired
public void setReadXmlDao(ReadXmlDao readXmlDao) {
this.readXmlDao = readXmlDao;
}

Resources