如何多次运行相同的代码来创建用户

时间:2015-12-09 19:40:11

标签: java

我创建了这个Selenium代码来创建新用户。它第一次工作正常。对于第二次运行,我必须更改用户名和电子邮件ID。我需要多次运行并自动创建用户。

driver.get("https://betaxxxxx.com");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

driver.findElement(By.id("cred_userid_inputtext")).sendKeys("xxx@yahoo.com");
driver.findElement(By.id("cred_password_inputtext")).sendKeys("GHin2.0!");

driver.findElement(By.id("cred_sign_in_button")).click();
driver.findElement(By.xpath(".//*[@id='navigation-menu']/li[2]/a")).click();
driver.findElement(By.xpath(".//*[@id='navigation-menu']/li[2]/ul/li[3]/a")).click();
driver.findElement(By.xpath(".//*[@id='navigation-menu']/li[2]/ul/li[3]/ul/li[2]/a")).click();
driver.findElement(By.id("first_name")).sendKeys("Automation");
driver.findElement(By.xpath(".//*[@id='last_name']")).sendKeys("Tester94001");
//driver.findElement(By.xpath("html/body/div[2]/div/div/div[5]/form/section[2]/div[2]/label[3]/span")).click();
Thread.sleep(3000);
driver.findElement(By.id("email")).sendKeys("xxx@yahoo.com");
driver.findElement(By.name("mobile")).sendKeys("xxx");
//driver.findElement(By.id("xxx_id")).sendKeys("xxx");
driver.findElement(By.xpath("html/body/div[2]/div/div/div[6]/form/div/section[1]/div[1]/div[2]/div/div/input")).sendKeys("xxx");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("html/body/div[2]/div/div/div[6]/form/div/section[1]/div[1]/div[2]/div/div/div/div[3]/div/span")).click();
driver.findElement(By.xpath("html/body/div[2]/div/div/div[6]/form/div/section[2]/div[1]/div/div/input")).sendKeys("xxxxx");
driver.findElement(By.xpath("html/body/div[2]/div/div/div[6]/form/div/section[2]/div[1]/div/div/div/div[3]/div")).click();
driver.findElement(By.xpath("html/body/div[2]/div/div/div[6]/form/section[4]/div[1]/label[4]/span")).click();
driver.findElement(By.id("address")).sendKeys("xxxxxxxx Corner Road");
driver.findElement(By.id("city")).sendKeys("xxxxxxx");
driver.findElement(By.xpath("html/body/div[2]/div/div/div[6]/form/section[6]/div[4]/div/select")).sendKeys("United States of America");
driver.findElement(By.xpath("html/body/div[2]/div/div/div[6]/form/section[6]/div[2]/div/select")).sendKeys("New Jersey");
driver.findElement(By.xpath(".//*[@id='postalcode']")).sendKeys("07931");
driver.findElement(By.xpath("html/body/div[2]/div/div/div[5]/div/div/div/div/a")).click();
driver.findElement(By.xpath("html/body/div[2]/div/div/div[2]/div/div/div/div/ul/li[2]/label")).click();
driver.findElement(By.xpath("html/body/div[2]/div/div/div[3]/div/div/section/div/div/label[1]/span")).click();



driver.findElements(By.name("modalrole"));
WebElement dropList = driver.findElement(By.name("modalrole"));
dropList.sendKeys("xxxxxxxxx");
List<WebElement> options = dropList.findElements(By.tagName("option"));
System.out.println("Total options -> "+ options.size());

"+options.get(i).getAttribute("selected"));//for(int i=0;i<options.size();i++){


//driver.findElement(By.xpath("html/body/div[2]/div/div/div[3]/div/div/div[2]/form[1]/div/div[2]/div[3]/div/div/input")). sendKeys("xxxx");
//driver.findElement(By.xpath("html/body/div[2]/div/div/div[3]/div/div/div[2]/form[1]/div/div[2]/div[3]/div/div/div/div[3]/div")).click();
driver.findElement(By.xpath("html/body/div[2]/div/div/div[3]/div/div/div[2]/form[1]/div/div[2]/div[4]/label[2]/span")).click();
driver.findElement(By.xpath("html/body/div[2]/div/div/div[3]/div/div/div[2]/form[1]/div/div[2]/div[4]/label[3]/span")).click();
driver.findElement(By.xpath("html/body/div[2]/div/div/div[3]/div/div/div[2]/form[1]/div/div[2]/div[5]/button[1]")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("html/body/div[2]/div/div/div[3]/div/div/div[2]/form[1]/div/div[2]/div[2]/div/div/input")).sendKeys("QAT");
Thread.sleep(3000);
driver.findElement(By.xpath("html/body/div[2]/div/div/div[3]/div/div/div[2]/form[1]/div/div[2]/div[2]/div/div/div/div[5]/div")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("html/body/div[2]/div/div/div[3]/div/div/div[2]/form[1]/div/div[2]/div[3]/div/div/input")). sendKeys("ABC");
Thread.sleep(3000);
driver.findElement(By.xpath(".//*[@id='clubsearchclubname_dropdown']/div[3]/div")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("html/body/div[2]/div/div/div[3]/div/div/div[2]/form[1]/div/div[2]/div[5]/button[1]")).click();

我在某些地方输入了xxxxx来隐藏一些身份。

1 个答案:

答案 0 :(得分:0)

您需要将用户和密码存储在其他位置并从该文件中读取。尝试创建属性文件 -

http://www.mkyong.com/java/java-properties-file-examples/

将用户ID和密码存储在属性文件中后,循环显示它们,您就可以在系统上创建多个用户。