仅在 Teamcity 上测试失败
Test fails on Teamcity only
我有一个测试(将文件上传到)在本地(在我的电脑上)完美运行,在 TC 上完美运行。
但!它仅在我 运行 MSTSC(我服务器上的远程桌面 - windows 服务器 2012)并实际观看测试 运行 时在 TC 上运行良好。
当触发器 运行 作为 TeamCity 构建代理的一部分并且 运行 我的测试而我不在远程桌面上时,它会失败。
顺便说一句,我还尝试了 运行 我在后台对 TeamCity 构建代理的测试,但它也失败了。
我正在单击一个元素以触发 windows 打开对话框弹出,然后使用以下内容:
public static void OpenFileNew(string FileNameToAttach)
{
Process pp = Process.GetCurrentProcess();
if (pp != null)
{
IntPtr h = pp.MainWindowHandle;
SetForegroundWindow(h);
}
SendKeys.SendWait("\\nas01\qa\TestFiles\" + FileNameToAttach);
Thread.Sleep(3000);
SendKeys.SendWait("{ENTER}");
Thread.Sleep(3000);
}
下一步是检查 td
标记名是否有特定文本。
上传文件后,td
应包含刚刚上传的完整文件名。
public bool CheckFileNameToUploadExists(string FullFileName)
{
bool IsFileExist = false;
WebDriverWait wait = new WebDriverWait(_webdriver, new TimeSpan(0, 0, 30));
var TDs = wait.Until(x => x.FindElements(By.TagName("td")));
for (int i = 0; i < TDs.Count - 1; i++)
{
var td = TDs[i].Text.ToString();
Thread.Sleep(2000);
_test.Log(LogStatus.Pass, td);
if(td == FullFileName)
IsFileExist = true;
}
return IsFileExist;
}
如果不存在则调用断言。这实际上是失败的。
当您离开远程桌面会话时,您就是 "killing" 桌面,无法 SetForegroundWindow
。
当您离开 RDP 会话时,您可以编写这个小脚本,而不是注销/关闭应用程序:
for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
%windir%\System32\tscon.exe %%s /dest:console
)
并且 运行 当您想以管理员身份退出会话时。
我有一个测试(将文件上传到)在本地(在我的电脑上)完美运行,在 TC 上完美运行。 但!它仅在我 运行 MSTSC(我服务器上的远程桌面 - windows 服务器 2012)并实际观看测试 运行 时在 TC 上运行良好。
当触发器 运行 作为 TeamCity 构建代理的一部分并且 运行 我的测试而我不在远程桌面上时,它会失败。 顺便说一句,我还尝试了 运行 我在后台对 TeamCity 构建代理的测试,但它也失败了。 我正在单击一个元素以触发 windows 打开对话框弹出,然后使用以下内容:
public static void OpenFileNew(string FileNameToAttach)
{
Process pp = Process.GetCurrentProcess();
if (pp != null)
{
IntPtr h = pp.MainWindowHandle;
SetForegroundWindow(h);
}
SendKeys.SendWait("\\nas01\qa\TestFiles\" + FileNameToAttach);
Thread.Sleep(3000);
SendKeys.SendWait("{ENTER}");
Thread.Sleep(3000);
}
下一步是检查 td
标记名是否有特定文本。
上传文件后,td
应包含刚刚上传的完整文件名。
public bool CheckFileNameToUploadExists(string FullFileName)
{
bool IsFileExist = false;
WebDriverWait wait = new WebDriverWait(_webdriver, new TimeSpan(0, 0, 30));
var TDs = wait.Until(x => x.FindElements(By.TagName("td")));
for (int i = 0; i < TDs.Count - 1; i++)
{
var td = TDs[i].Text.ToString();
Thread.Sleep(2000);
_test.Log(LogStatus.Pass, td);
if(td == FullFileName)
IsFileExist = true;
}
return IsFileExist;
}
如果不存在则调用断言。这实际上是失败的。
当您离开远程桌面会话时,您就是 "killing" 桌面,无法 SetForegroundWindow
。
当您离开 RDP 会话时,您可以编写这个小脚本,而不是注销/关闭应用程序:
for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
%windir%\System32\tscon.exe %%s /dest:console
)
并且 运行 当您想以管理员身份退出会话时。