资源:VS 2017,Selenium webdriver 3.8,Nunit 3.9,FF 56
使用这种方法我们怎么能顺序运行多个浏览器?我知道我们可以在Nunit中进行并行执行,但我想顺序执行。我在概念上和实用上都陷入困境。任何评论将不胜感激。
这是一个GlobalConfig.xml - 在这里给出键值对
<?xml version="1.0" encoding="utf-8" ?>
<Automation>
<RunSettings>
<AppURL>https:/abcd.com/Login/Login.aspx</AppURL>
<BrowserType>Firefox</BrowserType>
<Username>user123</Username>
<Password>pass123</Password>
</RunSettings>
</Automation>
这是setting.cs - 在这里定义属性
namespace Automation.Config
{
public class Settings
{
public static string AppURL { get; set; }
public static string Username { get; set; }
public static string Password { get; set; }
public static string BrowserType { get; set; }
}
}
这是configReader.cs - 使用XPathItem类来呈现项目
namespace Automation.Config
{
public class ConfigReader
{
public static void FrameworkConfigSettings()
{
XPathItem appUrl;
XPathItem username;
XPathItem password;
XPathItem browserType;
string strFilename = TestContext.CurrentContext.TestDirectory.ToString() + "\\Config\\GlobalConfig.xml";
FileStream stream = new FileStream(strFilename, FileMode.Open);
XPathDocument document = new XPathDocument(stream);
XPathNavigator navigator = document.CreateNavigator();
//Get XML Details and pass it in XPathItem type variables
// get node content by using simple xpath expression and C#
appUrl = navigator.SelectSingleNode("Automation/RunSettings/AppURL");
username = navigator.SelectSingleNode("Automation/RunSettings/Username");
password = navigator.SelectSingleNode("Automation/RunSettings/Password");
browserType = navigator.SelectSingleNode("Automation/RunSettings/BrowserType");
//Set XML Details in the property to be used accross framework
Settings.AppURL = appUrl.Value.ToString();
Settings.Username = username.Value.ToString();
Settings.Password = password.Value.ToString();
Settings.BrowserType = browserType.Value.ToString();
}
}
}
driver.cs class - 这是获取浏览器字符串名称的驱动程序类。
public static void Initialize(string browser)
{
if (browser.Equals(Constant.Chrome))
{
ChromeOptions options = new ChromeOptions();
Instance = new ChromeDriver(DrivePath, options, TimeSpan.FromSeconds(100));
Instance.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
}
else if(browser.Equals(Constant.Firefox))
{
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(DrivePath);
service.FirefoxBinaryPath = DrivePath;
var profile = new FirefoxProfile();
profile.AcceptUntrustedCertificates = true;
var options = new FirefoxOptions();
options.AcceptInsecureCertificates = true;
options.Profile = profile;
Instance = new FirefoxDriver(service.FirefoxBinaryPath, options, TimeSpan.FromSeconds(100));
Instance.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
}
}