Я хочу создать переменную webdriver, которую я могу вызвать во всех своих тестах. В настоящее время для отображения используется следующий пример.C#, selenium webdriver
Здесь я определяю мой WebDriver Я хочу использовать:
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.PhantomJS;
namespace WebAuto
{
public class OpenBrowser
{
private static IWebDriver driver = new ChromeDriver();
public IWebDriver getDriver()
{
return driver;
}
}
}
Теперь я хочу, чтобы назвать это WebDriver в другом тесте называется Логин:
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.PhantomJS;
namespace WebAuto
{
public class Login
{
public static void Login1()
{
//var driver = new ChromeDriver();
OpenBrowser.IWebDriver. getDriver();
driver.Navigate().GoToUrl("www.anywebsite.com");
//driver.Navigate().GoToUrl("www.anywebsite.com");
//driver.WaitForPageToLoad();
var inputtext1 = driver.FindElement(By.Id("lgLogin_txtUserId"));
//inputtext1.Focus();
inputtext1.SendKeys("User");
var inputpassword1 = driver.FindElement(By.Id("lgLogin_txtPassword"));
//inputpassword1.Focus();
inputpassword1.SendKeys("Password");
var inputbutton1 = driver.FindElement(By.Id("btnLoginClient"));
inputbutton1.Click();
//driver.WaitForPageToLoad();
}
}
}
Может кто-нибудь объяснить, что мне не хватает? ???
Эй, @hthomas. Можете ли вы поделиться сообщением об ошибке, которое вы видите с нами? Скомпилирована ли программа? Или он выполняется, но поступает неправильно? – allonhadaya