我创建了一个不同的类来调用屏幕截图。以下是我的代码
Program.cs
static int i=1;
[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
[TestFixture(typeof(ChromeDriver))]
public class TestWithMultipleBrowsers<TWebDriver> where TWebDriver : IWebDriver, new()
{
[Test]
public void Initialize()
{
PropertiesCollection.driver = new TWebDriver();
CredentialPageObject objSignin = new CredentialPageObject();
string pathfile = @"..\..\a.xlsx";
string sheetName = "SignIn";
var excelFile = new ExcelQueryFactory(pathfile);
var abc = from a in excelFile.Worksheet(sheetName) select a;
foreach (var a in abc)
{
PropertiesCollection.driver.Navigate().GoToUrl(a["URL"]);
}
PropertiesCollection.driver.Manage().Window.Maximize();
foreach (var a in abc)
{
objSignin.Login(a["ID"], a["Pass"]);
}
Result.screenshoot();
FunctionPageObject objFunc = new FunctionPageObject();
}
从包含的Result.cs类调用屏幕截图
class Result
{
public static void screenshot()
{
ITakesScreenshot screenshotDriver = PropertiesCollection.driver as ITakesScreenshot;
Screenshot screenCapture = screenshotDriver.GetScreenshot();
string path = @"..\..\Results\";
string timestamp = DateTime.Now.ToString("yy-MM-dd hh-mm-ss");
screenCapture.SaveAsFile(@path + i + ". " + timestamp + ".png", System.Drawing.Imaging.ImageFormat.Png);
}
}
这个是我的FunctionPageObject.cs
[FindsBy(How = How.Name, Using = "Login")]
public IWebElement clickLogin { get; set; }
[FindsBy(How = How.XPath, Using = "/html/body/form/table/tbody/tr[1]/td[2]/span/select/option[2]")]
public IWebElement Title { get; set; }
[FindsBy(How = How.Id, Using = "Initial")]
public IWebElement Initial { get; set; }
[FindsBy(How = How.Id, Using = "FirstName")]
public IWebElement FN { get; set; }
[FindsBy(How = How.Id, Using = "MiddleName")]
public IWebElement MN { get; set; }
[FindsBy(How = How.XPath, Using = "/html/body/form/table/tbody/tr[5]/td[2]/input[1]")]
public IWebElement Gender { get; set; }
[FindsBy(How = How.Name, Using = "Hindi")]
public IWebElement Language { get; set; }
public void CuteEditor()
{
Thread.Sleep(3000);
Title.Click();
Result.screenshot();
Initial.EnterText("PS");
Result.screenshot();
FN.EnterText("Pramukh");
Result.screenshot();
MN.EnterText("Swami");
Result.screenshot();
Gender.Click();
Result.screenshot();
Language.Click();
Result.screenshot();
现在,我在这里做的是从Result.Cs调用屏幕截图页面并在main和FunctionPageObject类中调用它,但它确实创建了屏幕截图,但它没有递增。
实际结果:始终为1 预期结果:应该一直增加。
答案 0 :(得分:0)
这将解决问题
class Result
{
static int i = 1 ;
public static void screenshot()
{
ITakesScreenshot screenshotDriver = PropertiesCollection.driver as ITakesScreenshot;
Screenshot screenCapture = screenshotDriver.GetScreenshot();
string path = @"..\..\Results\";
string timestamp = DateTime.Now.ToString("yy-MM-dd hh-mm-ss");
screenCapture.SaveAsFile(@path + i + ". " + timestamp + ".png", System.Drawing.Imaging.ImageFormat.Png);
i++;
}
}