java+selenium在聯通北分專案上自動新增裝置
阿新 • • 發佈:2018-12-10
指令碼是基於聯通北分專案完成的 語言為Java 框架為selenium 經過測試可正常使用,分享指令碼如下
package test; import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.Select; import org.testng.annotations.Test; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.NoSuchElementException; public class addOneDevice { @Test public void test() throws InterruptedException { System.setProperty("webdriver.chrome.driver","D:/software/Tools/eclipse+selenium_tools/chromedriver.exe"); WebDriver dr= new ChromeDriver(); dr.manage().window().maximize(); //此處是生產環境,以***代替 dr.get("*****"); //*[@id="container_login"]/div[1]/img WebElement loginUser = dr.findElement(By.xpath("//*[@id=\"username\"]")); loginUser.clear(); loginUser.sendKeys("admin"); WebElement login_pswd = dr.findElement(By.xpath("//*[@id=\"password\"]")); login_pswd.clear(); login_pswd.sendKeys("iradar"); WebElement login_enter = dr.findElement(By.xpath("//*[@id=\"enter\"]")); login_enter.click(); Thread.sleep(2000); //此處環境是生產環境,以***代替 dr.get("××××"); Thread.sleep(3000); WebElement add_device = dr.findElement(By.cssSelector("a.tipso_style")); add_device.click(); WebElement hosts = dr.findElement(By.xpath("//*[@id=\"host\"]")); hosts.sendKeys("windows_1"); WebElement hostsVisiblename = dr.findElement(By.xpath("//*[@id=\"visiblename\"]")); hostsVisiblename.sendKeys("windows_1_1"); Select rightbar =new Select(dr.findElement(By.xpath("//*[@id=\"groups_right\"]"))); rightbar.selectByValue("102"); WebElement addbutton = dr.findElement(By.xpath("//*[@id=\"add\"]")); addbutton.click(); WebElement hostIp = dr.findElement(By.xpath("//*[@id=\"hostInterfaceRow_1\"]/td[2]/input")); hostIp.clear(); hostIp.sendKeys("192.168.202.218"); WebElement hostInterface = dr.findElement(By.xpath("//*[@id=\"hostInterfaceRow_1\"]/td[5]/input")); hostInterface.clear(); hostInterface.sendKeys("10050"); WebElement templateButton = dr.findElement(By.xpath("//*[@id=\"tab_templateTab\"]")); templateButton.click(); WebElement chooseButton = dr.findElement(By.xpath("//*[@id=\"newTemplateTable\"]/tbody/tr[1]/td/div/input")); chooseButton.click(); dr.switchTo().frame("ifr_rda_popup"); Thread.sleep(2000); List els = dr.findElements(By.xpath("//input[@type='checkbox']")); els.get(els.size()-7).click(); dr.findElement(By.xpath("//*[@id=\"select\"]")).click(); dr.switchTo().defaultContent(); dr.findElement(By.xpath("//*[@id=\"add_template\"]")).click(); dr.findElement(By.xpath("//*[@id=\"save\"]")).click(); Thread.sleep(3000); dr.quit(); } }