我是java / testNg的新手我尝试运行您输入人员编号的代码,然后该用户将通过网页添加到数据库中。虽然代码允许我输入msisdn,但不会通过网页执行操作。 以下是我的代码:
package firsttestng1;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
//adding subscriber class
public class subscribers {
public String baseUrl = "http://testpage.ie";
public WebDriver driver = new FirefoxDriver();
public String msisdn;
//set members number
public void setSubscriber(String subscribrNmbr){
msisdn=subscribrNmbr;
}
//get subscribers number
public String getSubscriber(){
return msisdn;
}
//adding subscriber method which should enter the subscribers number once it is entered
public void addMembers(){
waitForElement("[title=\"Run\"]",false);
driver.findElement(By.linkText("Policy")).click();
waitForElement("[title=\"SPCM\"]",false);
driver.findElement(By.linkText("Memebers")).click();
waitForElement("[title=\"Memembers Mgmt\"]",false);
driver.findElement(By.linkText("MemberMgmt")).click();
waitForElement("[title=\"Subscribers\"]",false);
driver.findElement(By.linkText("Members Page")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.id("add_label")).click();
driver.findElement(By.id("subscriberIdentifier.msisdn")).click();
driver.findElement(By.id("subscriberIdentifier.msisdn")).sendKeys(""+getSubscriber());
driver.findElement(By.id("subscriberIdentifier.imsi")).click();
driver.findElement(By.id("subscriberIdentifier.imsi")).sendKeys(""+getSubscriber());
driver.findElement(By.id("subscriberIdentifier.imsi")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.id("submitSubscriberButton_label")).click();
if(isAlertPresent()){
driver.switchTo().alert();
driver.switchTo().alert().accept();
}
package firsttestng1;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.testng.Assert;
import org.testng.annotations.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.Keys;
import java.util.Scanner;
public class FirsttestNGFile {
//launch Firefox and enter login details
@BeforeTest
public void launchBrowser(){
driver.get(baseUrl);
driver.findElement(By.id("username")).sendKeys("test");
driver.findElement(By.id("password")).sendKeys("test");
driver.findElement(By.name("login")).click();
driver.manage().window().maximize();
}
//main method
@Test
private void addSubscriber() {
Scanner input = new Scanner(System.in);
subscribers nwsubscriber = new subscribers();
System.out.println("Enter misidn");
String temp = input.nextLine();
nwsubscriber.setSubscriber(temp);
}
}
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="FirstTestNG1.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar"/>
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
<target name="AWTConsole">
<java classname="bsh.util.AWTConsole" failonerror="true" fork="yes">
<classpath refid="FirstTestNG1.classpath"/>
</java>
</target>
</project>