我确实希望得到关于如何通过C#连接已经开放的浏览器的指南。
这个问题在我的文字开发时间中占30%左右!
我确实希望得到关于如何通过C#连接已经开放的浏览器的指南。
这个问题在我的文字开发时间中占30%左右!
您可具体说明在[FixtureSetUp]和[《试验清单》]中开始和关闭浏览器,并从[SetUp]和[TearDown]中删除。 所有的[测试]测试都将在同一浏览器中进行。 因此,如果你有10个班级,其中每个班有5个测试,而不是50个浏览器开关和关闭,只有10个班。
public IWebDriver driver { get; private set; };
[TestFixtureSetUp]
public void TestFixtureSetup()
{
driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.google.com/");
}
[TestFixtureTearDown]
public void TestFixtureTearDown()
{
driver.Quit();
}
如果你想打开并关闭你的浏览器,你就可以从基数类别继承[试验纤维”和[试验纤维]方法,如果你有一个试验类别在他人之前执行(测试)并且最后执行(Z_test)的话,你可以确定并揭开一些旗帜,以表明我们是否应当开始浏览器:
namespace Tests
{
[TestFixture]
public abstract class Test
{
private static bool _flagSetUp;
private static bool _flagTearDown;
public IWebDriver driver { get; private set; };
protected Test()
{
}
public static void SetFlag(bool flagSetUp, bool flagTearDown)
{
_flagSetUp = flagSetUp;
_flagTearDown = flagTearDown;
}
[TestFixtureSetUp]
public void TestFixtureSetup()
{
if(_flagSetUp)
{
driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.google.com/");
_flagSetUp = false;
}
}
[TestFixtureTearDown]
public void TestFixtureTearDown()
{
if(_flagTearDown)
{
driver.Quit();
}
}
}
namespace Tests
{
[TestFixture(new object[] { true, false })]
public class A_Test : Test
{
public A_Test(bool flagSetUp, bool flagTearDown)
{
SetFlag(flagSetUp, flagTearDown);
}
[Test]
public void Test1()
{
...
}
}
namespace Tests
{
[TestFixture(new object[] { false, true })]
public class Z_Test : Test
{
public A_Test(bool flagSetUp, bool flagTearDown)
{
SetFlag(flagSetUp, flagTearDown);
}
[Test]
public void Test2()
{
...
}
}
The last workaround looks like not good solution. Althouth first workaround also doesn t guarantee 100% tests isolation (btw don t forget to write driver.Navigate().GoToUrl("http://www.google.com/");
as first step for each test). So probably the best solution will be parallel execution and Setup, Teardown methods for each test.
因为时间是你的首要问题,这在本地没有得到支持。 为什么采取替代做法。 开发/实施基本连接和安放;与家用页相连接。 然后,将这一类别扩大到你更复杂的使用案例。 替代 测试个案控制员然后使用工厂来检查你的详细测试,将网上浏览器通过测试。
你可以同时进行测试,但在你准备进行所有测试时,这只是一个好的想法。 下面是你在重新制定和管理新编纂的法典时可以使用的想法。
将其网络驱动器{浏览器}试射入一个文件(或如果你愿意在视窗服务中保存),然后检索(转换)每当你发射网络驱动器时就将文件存档。 不过,网络驱动器的源码却很少使用。
当我有一段时间时,我将在此更新我的回答。 我希望Stack Overflow将使我能够像现在这样 past忙地改变法典。 此外,我仍应在埃里克的答复和评论中给他以信用。 尽管我的想法是开始(使网络司机更快)。
。 NET:Serializing Object to a file from a 3rd party Assembly (to make Selenium Webhangr increase)
================================================================================================================================================================================================================================================================
<>Simplelogical:
如果序列物体档案存在t=>开放式浏览器是正常的,并创建文档
如果序列化物体档案存在=>将物体存档为物体=>设定的浏览器,等于脱硫物体(当然是正确的预测)
================================================================================================================================================================================================================================================================
The other requirement is that you put in a condition into your method decorated with the [TearDown] attribute so your browser doesn t close when the script (test) finishes. The first time through, it ll take time to open it up. But once that browser window is open, you re good to go.
[TearDown]
public void TeardownTest()
{
try
{
if (Config.CLOSE_BROWSER_AFTER_TEST_CASE)
{
driver.Quit();
}
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
您可使用以下代码样本来完成这项任务
IWebDriver WebDriver = null;
try
{
System.Uri uri = new System.Uri("http://localhost:7055/hub");
WebDriver = new RemoteWebDriver(uri, DesiredCapabilities.Firefox());
Console.WriteLine("Executed on remote driver");
}
catch (Exception)
{
WebDriver = new FirefoxDriver();
Console.WriteLine("Executed on New FireFox driver");
}
if a firefox browser is opened using a Firefox web driver, you can use Remote WebDriver to use that browser instance. So First I try to initialize a Remote Web Driver, if no instance is running, then try block will fail and Catch block will open the Firefox driver. Now for example, your script fails on a specific location and the browser remained open. Now again run that initialization code, the try block will pass this time and remote web Driver will use the existing opened browser. (No new browser window will open).
Put this initialization in your Test Startup method
This block of code saves my ample amount of time.
I have also written a blog post on it.
You can read it here.
http://www.binaryclips.com/2016/03/selenium-web-driver-in-c-how-to.html
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...