# Created by Mick Jagger at 1/13/2021
@login
Feature: Login
Scenario: Login to Website Homepage
When Launch website
Then Enter username and password
And Log in
然后使相应的步骤文件如下所示:
package glue;
import cucumber.api.java.en.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import java.util.List;
public class LoginSteps extends Driver {
public String username = "username";
public String password = "password";
@When("Launch Website")
public void launch_website() throws Throwable {
driver.get("https://www.website.com/");
Thread.sleep(2000);
}
@Then("^Enter username and password$")
public void enter_credentials() throws Throwable {
driver.findElement(By.xpath("//input[@aria-label='Phone number, username, or email']")).sendKeys(username);
driver.findElement(By.xpath("//input[@aria-label='Password']")).sendKeys(password);
}
@And("^Log in$")
public void log_in() throws Throwable {
Thread.sleep(1000);
List<WebElement> buttons = driver.findElements(By.tagName("button"));
buttons.get(1).click();
Thread.sleep(2000);
driver.findElement(By.tagName("button")).click();
Thread.sleep(1000);
buttons = driver.findElements(By.xpath("//button[@tabindex='0']"));
buttons.get(1).click();
}
}
是的,您应该为每个功能创建一个新文件。例如,login.gherkin、upload.gherkin、logout.gherkin
抱歉,我不知道你说的是Python,但这是相同的想法
每个文件应具有如下布局:
然后使相应的步骤文件如下所示:
如果您不熟悉浏览器自动化,我建议您学习“页面对象模型方法”。而且,我不再使用这个恼人的框架,它本应该让事情变得更简单,但对我来说,它只是增加了额外的工作
相关问题 更多 >
编程相关推荐