我正在设置CCNET服务器来运行Selenium测试。在我的测试代码中,我使用以下命令启动Selenium RC服务器,如果它没有运行:
var proc = new Process();
proc.StartInfo.WorkingDirectory = Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, @"..\..\..\..\..\lib\SeleniumRC\selenium-server-1.0-beta-2");
proc.StartInfo.FileName = "java"; //have also tried with "java.exe"
proc.StartInfo.Arguments = @"-jar selenium-server.jar -multiWindow -trustAllSSLCertificates -firefoxProfileTemplate ""..\Firefox Profiles\Relaxed Security""";
proc.StartInfo.UseShellExecute = true;
proc.Start();
这在我的开发机器上很有用。但是,当我从CCNET.exe(在用户上下文中)运行它时,我可以看到,不是执行java.exe进程,而是弹出一个“c:\ windows \ java”的资源管理器窗口。我认为我的路径设置搞砸了,但我不确定如何。你能帮忙吗?
答案 0 :(得分:2)
您是否尝试过在命令提示符下的运行目录下运行它的用户上下文并尝试使用命令行?
如果路径设置混乱,您可以通过右键单击我的电脑,属性,高级,环境变量...来调整它们。
答案 1 :(得分:2)
我这样做是为了在后台启动服务器:
// Start the java server
Process seleniumServer;
String javaFileLocation = @"C:\Program Files\Java\jre6\bin\java.exe";
String jarFileLocation = @"C:\SeleniumRC\selenium-remote-control-1.0.1\selenium-server-1.0.1\selenium-server.jar";
seleniumServer = new Process();
seleniumServer.StartInfo.FileName = javaFileLocation;
seleniumServer.StartInfo.Arguments = "-jar " + jarFileLocation;
seleniumServer.StartInfo.WorkingDirectory = jarFileLocation.Substring(0, jarFileLocation.LastIndexOf("\\"));
seleniumServer.StartInfo.UseShellExecute = true;
seleniumServer.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
seleniumServer.Start();
然后就做了
seleniumServer.Kill()
在一切顺利之后停止它。
不确定这会对CCNET的情况有所帮助,但可能会帮助人们在将来寻找这种情况吗?
答案 2 :(得分:1)
我用这个
公共课Navegador:DefaultSelenium { private static int contadorPorta = 4444;
private int porta;
private delegate string OperacaoSelenium();
// Variável para a URL Base
private string urlBase;
public string UrlBase
{
get { return urlBase; }
}
public Navegador(string urlBase)
: base("localhost", contadorPorta, "*firefox", urlBase) // ou *firefox ou *chrome *safari, *opera , *iexplore etc.
{
this.urlBase = urlBase;
porta = Navegador.contadorPorta;
// Deve sempre abrir o Selenium RC-Server antes (instância única - Singleton)
this.IniciarSeleniumRCServer();
Navegador.contadorPorta++;
this.Start();
this.Open("/");
}
/// <summary>
/// Inicia o Selenium RC-Server, que é o arquivo JAR que vem no pacote do Selenium RC
/// </summary>
private void IniciarSeleniumRCServer()
{
string seleniumParameters = "..\\..\\..\\ExternalLibraries\\selenium-remote-control-1.0-beta-1\\selenium-server-1.0-beta-1\\selenium-server.jar -Dhttp.proxyHost=10.100.100.24 -port " + porta + "";
procSeleniumServer = System.Diagnostics.Process.Start("java.exe", " -jar " + seleniumParameters);
System.Threading.Thread.Sleep(1000);
}
效果很好..但不是代理-.-'
答案 3 :(得分:1)
SeleniumProcess类
public class SeleniumProcess
{
private static Process _seleniumServer;
public static void Start()
{
_seleniumServer = new Process
{
StartInfo =
{
FileName = "java",
Arguments =
"-jar ../../../References/" +
"selenium-remote-control-1.0.3/" +
"selenium-server-1.0.3/" + "selenium-server.jar -port 4444"
}
};
_seleniumServer.Start();
}
public static void Stop()
{
_seleniumServer.Kill();
}
}
[SetUp]
public void SetupTest()
{
SeleniumProcess.Start();
}
[TearDown]
public void TeardownTest()
{
try
{
_selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
SeleniumProcess.Stop();
Assert.AreEqual("", _verificationErrors.ToString());
}
#endregion