Try to declare Webdriver
instance variable as static
inside your test class
and initialize only once. Your behavior is because different webdriver instances does not share the same session
, so therefore you have always to login into desired page.
restore current sections for next test case in Selenium scripts
-
30-07-2021 - |
Question
I am using selwnium web driver. When I am using selenium and nunit to run my test cases I find that every time a test case starts it open a new page and when its done the mew page will be destoryed. Therefore I have to open new page and login in every test case.
I want to have my test cases share one single webpage so that they can be performed in sequence.
Is a selenium limitation, or is it a way to implement it?
Thank you!
Pas de solution correcte
Autres conseils
You probably using @Before , @After
annotation.
Try use @BeforeClass, @AfterClass
instead. e.g:
....
static WebDriver driver;
@BeforeClass
public static void firefoxSetUp() throws MalformedURLException {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.manage().window().setSize(new Dimension(1920, 1080));
}
@Before
public void homePageRefresh() throws IOException {
driver.manage().deleteAllCookies();
driver.get(propertyKeysLoader("login.base.url"));
}
@AfterClass
public static void closeFirefox(){
driver.quit();
}
.....
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow