J'ai écrit un fichier de fonctionnalité en concombre avec Java pour une opération de connexion. Je souhaite effectuer uniquement une opération de connexion plusieurs fois une fois que l'application a été lancée sans fermer l'application.
Fichier de fonctionnalité P>
<html> <head> <title>Login</title> </head> <body> <div align="center"> Username<input type="text" id="user"></br></br> Password<input type="password" id="pass"></br></br> <input type="button" value="Login" id="btn"> </div> </body> </html>
3 Réponses :
Zone de mise au point: forte> Vous excluez le lancement et la fermeture du navigateur du contour des scénarios Comme nous allons le garder sous les annotations testtrunner.java < / strong> p> drivermanager.java strong> p>
Vous devez utiliser le scénario avec Tableaux de données kbd> pour itérer la même étape plusieurs fois sans fermer le navigateur. modifier votre fichier de fonctionnalité comme ci-dessous. P> @Given("validate the credentials:")
public void validate_the_credentials(List<String> animals) {
}
package steps;
import java.util.Map;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import cucumber.api.DataTable;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;
public class Test {
WebDriver driver;
String gecko="webdriver.chrome.driver";
String path="./drivers/chromedriver1.exe";
@Given("^I open the application$")
public void i_open_the_application() throws Throwable {
System.setProperty(gecko, path);
driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get("file:///C:/Users/AZ/Desktop/webpages/loginPage.html");
}
@When("^I enter username and password$")
public void i_enter_username_and_password(DataTable table) throws Throwable {
for (Map<String,String> data : table.asMaps(String.class,String.class)) {
driver.findElement(By.id("user")).sendKeys(data.get("username"));
driver.findElement(By.id("pass")).sendKeys(data.get("password"));
driver.findElement(By.id("btn")).click();
Thread.sleep(3000);
driver.navigate().refresh();
Thread.sleep(3000);
}
}
@When("^I close the application$")
public void i_close_the_application() throws Throwable {
driver.close();
}
}