我尝试使用 Katalon Studio 和 Selenium|testNG 自动登录。我已使用 XML 文件将浏览器值发送到我已粘贴到此处的脚本。
public class TC_Testportal {
private WebDriver driver;
private String baseUrl;
@Parameters("browser")
@BeforeMethod
public void beforeMethod(String browser) {
if (browser.equals("firefox")) {
System.setProperty("webdriver.gecko.driver", "drivers\\geckodriver.exe");
driver = new FirefoxDriver();
baseUrl = "https://test.com";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
} else if (browser.equals("chrome")) {
System.setProperty("webdriver.chrome.driver", "drivers\\chromedriver.exe");
driver = new ChromeDriver();
baseUrl = "https://test.com";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
}
@Test
public void tc001() {
driver.get(baseUrl);
//Empty user-name|password validation
driver.findElement(By.xpath("//input[@id='username']")).click();
driver.findElement(By.xpath("//input[@id='username']")).clear();
driver.findElement(By.xpath("//input[@id='username']")).sendKeys("");
driver.findElement(By.xpath("//input[@id='userpassword']")).click();
driver.findElement(By.xpath("//input[@id='userpassword']")).clear();
driver.findElement(By.xpath("//input[@id='userpassword']")).sendKeys("");
driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)='SIGN IN'])[1]/following::div[2]")).click();
System.out.println("Empty user-name|password validation - CHECKED");
//Empty password validation
driver.findElement(By.xpath("//input[@id='username']")).click();
driver.findElement(By.xpath("//input[@id='username']")).clear();
driver.findElement(By.xpath("//input[@id='username']")).sendKeys("test");
driver.findElement(By.xpath("//input[@id='userpassword']")).click();
driver.findElement(By.xpath("//input[@id='userpassword']")).clear();
driver.findElement(By.xpath("//input[@id='userpassword']")).sendKeys("");
driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)='SIGN IN'])[1]/following::button[1]")).click();
System.out.println("Empty password validation - CHECKED");
//Empty user-name validation
driver.findElement(By.xpath("//input[@id='username']")).click();
driver.findElement(By.xpath("//input[@id='username']")).clear();
driver.findElement(By.xpath("//input[@id='username']")).sendKeys("");
driver.findElement(By.xpath("//input[@id='userpassword']")).click();
driver.findElement(By.xpath("//input[@id='userpassword']")).clear();
driver.findElement(By.xpath("//input[@id='userpassword']")).sendKeys("123");
driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)='SIGN IN'])[1]/following::div[2]")).click();
System.out.println("Empty user-name validation - CHECKED");
}
@AfterMethod
public void afterMethod() {
driver.quit();
}
}
我只是想知道我的代码构造是否会被 QA 行业接受,因为我是测试自动化的新手。而且,如果它不在可接受的范围内,如果您能给我指导以提高我的知识,我将不胜感激。
任何与代码构造/代码质量/参数命名/测试用例编号等相关的建议/建议将不胜感激。