Could not find the preLaunchTask 'npm' - visual-studio-code

I'm trying to write a simple Hello World console application using VS Code. Following is what I have in my program.cs which I have created
using system;
namespace MySpace
{
public static class MyClass
{
public static void Main(string[] args)
{
Console.WriteLine("Hello");
}
}
}
When I hit F5, it says "Could not find the preLaunchTask 'npm'."
What am I doing wrong??

Related

Unable to open chromedriver in eclipse

I'm facing errors while trying to execute a simple code to launch a chrome browser and open google.com but not able to launch the browser. Attached is the error message.
This is the code -
package gmailpkg;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
public class login {
public static String driverPath = "X:/JARs-Setup/chromedriver_win32/";
public static WebDriver driver;
public static void main(String []args) throws InterruptedException {
System.out.println("launching chrome browser");
System.setProperty("webdriver.chrome.driver", driverPath+"chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://google.com");
Thread.sleep(2000);
//driver.manage().window().maximize();
Thread.sleep(2000);
driver.findElement(By.xpath( "//*[#href='https://mail.google.com/mail/?tab=wm']")).click();
}
}

i cant add toast in libgdx

im trying to create toast by call it with interface
the interface works fine it just that when i try to make a toast with it, it crashes
in Android Launcher
public class AndroidLauncher extends AndroidApplication implements Interface {
public void tost() {
Toast.makeText(getContext(), "wrong num",
Toast.LENGTH_LONG).show();}}
in gameclass
interface Interface{void tost();}
public class MyGdxGame extends ApplicationAdapter {
final private Interface interface;
public MyGdxGame(Interface interface){this.interface=interface;}
public void render() {interface.tost}
Android toasts must be performed on the Android UI thread. The game loop in LibGDX runs on the OpenGL thread, so you must post your method to the UI thread to safely run it, like this:
public class AndroidLauncher extends AndroidApplication implements Interface {
public void tost() {
runOnUiThread(new Runnable() {
#Override
public void run () {
Toast.makeText(getContext(), "wrong num",
Toast.LENGTH_LONG).show();}
}
});
}
}

MEF giving CompositionException

I am new to MEF and I am trying this following program.
The class library whose dll I am making has following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.Composition;
namespace MefTestsCore
{
[Export (typeof(MefTestsCore.IFace))]
public class CoreClass1 : IFace
{
public String getName()
{
return "CoreClass1";
}
}
interface IFace
{
String getName();
}
}
The program which wants to access the dll has following code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using MefTestsCore;
namespace MefTests
{
class Program
{
[Import (typeof(MefTestsCore.IFace), AllowRecomposition=true)]
public IFace iFaceObj;
static void Main(string[] args)
{
Program p = new Program();
p.Method();
}
public void Method()
{
DirectoryCatalog catalog = new DirectoryCatalog(#"C:\Users\username");
CompositionContainer container = new CompositionContainer(catalog);
container.ComposeParts(this);
Console.WriteLine(iFaceObj.getName());
Console.ReadKey();
}
}
}
I have the MEFLibrary.dll (dll containing MefTestsCore namespace, the first part of above code) at C:\Users\username. When I run the program, it throws CompositionException with following details
The composition produced a single composition error.
The root cause is provided below. Review the CompositionException.Errors property for more detailed information.
1) The export 'MefTestsCore.CoreClass1 (ContractName="MefTestsCore.IFace")' is not assignable to type 'MefTestsCore.IFace'.
Resulting in: Cannot set import 'MefTests.Program.iFaceObj (ContractName="MefTestsCore.IFace")' on part 'MefTests.Program'.
Element: MefTests.Program.iFaceObj (ContractName="MefTestsCore.IFace") --> MefTests.Program
In your test program you are using MefTestsCore. So I assume you referenced that assembly from your test program. But then you also load a copy from c:\Users\username. Now they types don't match because they come from different assemblies.
You have to put the interface into it's own assembly so that you then can reference it from your program and from MefTestsCore.

Running a public static void main in Groovy Eclipse

Sorry Groovy Noob here:
Here is my Groovy Class -
class MyClass {
static void main() {
println("Hello World");
}
...
How do I run this classin Eclipse STS? I want to keep the main method. I do not want to change this to just a script.
Thanks
To initiate a method, main you must pass in a string array (String[] something). Use the following.
public static void main(String[] args)
{
System.out.println("Hello World")!
}
Remember... a Groovy class is a Java class. All you need to do is right-click -> Run as -> Java application.

Starting Selenium with custom Firefox profile from Eclipse

I'm running Selenium tests from within Eclipse, but I can't load a custom Firefox profile.
Most sources suggest I need to launch the Selenium Server like this:
java -jar selenium-server.jar -firefoxProfileTemplate </path/to/template/>
But when launching my test from within Eclipse it doesn't use that - the tests will run if the Selenium Server isn't running.
This thread suggests that I can set the profile in the DefaultSelenium constructor:
Selenium RC - disabling browser cookie
But the code generated for me by Selenium IDE (Firefox plugin) doesn't use that constructor:
package com.example.tests;
import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
public class Example extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://www.example.com/", "*firefox");
}
public void testExample() throws Exception {
selenium.open("/");
selenium.click("//body");
}
}
Where should I set the DefaultSelenium configuration options? Or is there some other method I can use to load my custom Firefox template?
Thanks!
Stu
I made a SeleniumTestCase that starts/stops the server before/after each test class and starts/stops the Selenium instance before/after each test:
public class SeleniumTestCase {
protected static Selenium selenium;
protected static AppNavUtils appNavUtils;
#BeforeClass
public static void setUpBeforeClass() throws Exception {
SeleniumServerControl.getInstance().startSeleniumServer();
}
#AfterClass
public static void tearDownAfterClass() throws Exception {
SeleniumServerControl.getInstance().stopSeleniumServer();
}
#Before
public void setUp() throws Exception {
// Replace "*chrome" with "*firefox" for Selenium > 1.0
selenium = new DefaultSelenium("localhost", 5444, "*chrome", "http://localhost:8080/");
selenium.start();
appNavUtils = new AppNavUtils(selenium);
}
#After
public void tearDown() throws Exception {
selenium.stop();
}
}
The SeleniumServerControl starts and stops the server:
public class SeleniumServerControl {
private static final SeleniumServerControl instance = new SeleniumServerControl();
public static SeleniumServerControl getInstance()
{
return instance;
}
private SeleniumServer server = null;
protected SeleniumServerControl(){}
public void startSeleniumServer() {
if (server == null) {
RemoteControlConfiguration rcc = new RemoteControlConfiguration();
rcc.setPort(5444);
//rcc.setFirefoxProfileTemplate(newFirefoxProfileTemplate)
server = new SeleniumServer(rcc);
}
server.start();
}
public void stopSeleniumServer()
{
if (server != null) {
server.stop();
server = null;
}
}
}
the version of code you have above assumes that you are running your tests against localhost on port 4444 thats why it is has 2 parameters in the setup.
To set up eclipse to run it you will need to update the run configuration. That is under
Run > Run Configurations
Have a look for the item that has selenium in it and add the config above so that when it runs it will pick it up and run.
I personally just fire up the server when I start working by running a batch file and kill it at the end of the day.