How to if I want to write an application that launches Firefox with arguments ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace Launcher
{
public static class Program
{
public static void Main(string[] args)
{
Process.Start("C:/Program Files/Mozilla Firefox/firefox.exe");//this is ok
Process.Start("C:/Program Files/Mozilla Firefox/firefox.exe -P MyProfile -no-remote");// this doesn't work
}
}
}
You will need to specify the process.StartInfo.Arguments
See this question: Calling an application from ASP.NET MVC
You will need to use the process.StartInfo.Arguments, as shown here:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace Launcher
{
public static class Program
{
public static void Main(string[] args)
{
Process firefox = new Process();
firefox.StartInfo.FileName = #"C:\Program Files\Mozilla Firefox\firefox.exe";
firefox.StartInfo.Arguments = "-P MyProfile -no-remote";
firefox.Start();
}
}
}
Related
How do I do this? Can this be done through code in C# ? I use this code to do this but it doesn't work .
using System;
using System.Diagnostics;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Process.Start(#"C:\wamp64\wampmanager.exe");
}
}
}
I want to create a variable webdriver that i can call in all of my tests.
I currently have the following example for display purposes.
Here I define my webdriver I want to use:
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.PhantomJS;
namespace WebAuto
{
public class OpenBrowser
{
private static IWebDriver driver = new ChromeDriver();
public IWebDriver getDriver()
{
return driver;
}
}
}
Now i want to call this webdriver in another Test called Login:
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.PhantomJS;
namespace WebAuto
{
public class Login
{
public static void Login1()
{
//var driver = new ChromeDriver();
OpenBrowser.IWebDriver. getDriver();
driver.Navigate().GoToUrl("www.anywebsite.com");
//driver.Navigate().GoToUrl("www.anywebsite.com");
//driver.WaitForPageToLoad();
var inputtext1 = driver.FindElement(By.Id("lgLogin_txtUserId"));
//inputtext1.Focus();
inputtext1.SendKeys("User");
var inputpassword1 = driver.FindElement(By.Id("lgLogin_txtPassword"));
//inputpassword1.Focus();
inputpassword1.SendKeys("Password");
var inputbutton1 = driver.FindElement(By.Id("btnLoginClient"));
inputbutton1.Click();
//driver.WaitForPageToLoad();
}
}
}
Could someone please explain what I am missing????
The way to call the driver from Login class is
OpenBrowser openBrowser = new OpenBrowser();
IWebDriver driver = openBrowser.getDriver();
Whenever I am using Window Forms It works Fine But it always give error with console applicion.
Error- The socket connection was aborted. This could be caused by an
error processing your message or a receive timeout being exceeded by
the remote host, or an underlying network resource issue. Local socket
timeout was '00:01:00'.
Here is My Code
Contract
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace ClassLibrary1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IReportService" in both code and config file together.
[ServiceContract(CallbackContract=typeof(IReportServiceCallbak))]
public interface IReportService
{
[OperationContract(IsOneWay=true)]
void ProcessReport();
}
public interface IReportServiceCallbak
{
[OperationContract(IsOneWay=true)]
void Progress(int percentage);
}
}
Service
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Threading;
namespace ClassLibrary1
{
public class ReportService : IReportService
{
public void ProcessReport()
{
for (int i = 0; i < 100; i++)
{
Thread.Sleep(50);
OperationContext.Current.GetCallbackChannel<IReportServiceCallbak>().Progress(i);
}
}
}
}
Client
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Threading.Tasks;
using System.Threading;
namespace DuplexClientsss
{
class Program
{
static void Main(string[] args)
{
new Tests();
} }
class Tests : ReportService.IReportServiceCallback
{
ReportService.ReportServiceClient obj;
public Tests()
{
obj = new ReportService.ReportServiceClient(new InstanceContext(this));
obj.ProcessReport();
}
public void Progress(int percentage)
{
Console.WriteLine(percentage);
}
}
}
new Task
(
()=>
{
obj.ProcessReport();
}
).Start();
I need to compile via csc.exe this code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Scripting;
namespace ConsoleApplication13
{
class Program
{
static void Main(string[] args)
{
Scripting.FileSystemObject fso = new Scripting.FileSystemObject();
Scripting.Folder folder = fso.GetFolder(#"E:\backup_SQL_Planet\");
Int64 dirSize = (Int64)folder.Size;
string abc = Convert.ToString(dirSize);
Console.WriteLine(abc);
}
}
}
when i execute csc.exe there was a problem with reference of (using Scripting;)
How do I reference using Scripting?
I'm using the VirtualBox type library from C# as follows:
using System;
using System.Collections.Generic;
using System.Text;
using VirtualBox;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
IVirtualBox vbox = new VirtualBoxClass();
IHost h = vbox.Host;
Array a = h.USBDevices;
}
}
}
The line Array a = h.USBDevices; causes a SafeArrayTypeMismatchException. Has anyone else had the same problem?
Thanks!
var a = (IUSBDevice[])h.USBDevices