任务5:要求使用log4j+ant+testng+selenium完成下列要求,实现无人值守的自动化测试
8
李焕贞
开始于 2021-05-04 09:36
0 2 94
已截止

任务尚未发布或者你没有权限查看任务内容。

任务讨论
4-陈涵
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

public class BaseTest {
	WebDriver driver;
	@BeforeClass
	public void initBrowser() {
		System.setProperty("webdriver.gecko.driver", "D:\\test\\geckodriver.exe");
		driver = new FirefoxDriver();
	}
	@AfterClass
	public void quitBrowser() {
		driver.quit();
	}
}
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;

public class AddMovie extends BaseTest{
	@Test
	public void test1() throws InterruptedException {
		driver.get("http://localhost:8032/mymovie/admin.php/Login/index.html");
		driver.findElement(By.name("username")).sendKeys("admin");
		driver.findElement(By.name("password")).sendKeys("admin");
		driver.findElement(By.xpath("//input[@type='submit']")).click();
		driver.findElement(By.xpath("//h2[contains(text(),'影片管理')]")).click();
		driver.findElement(By.xpath("//span[contains(.,'添加影片信息')]")).click();
		Thread.sleep(2000);
		
		WebElement filename = driver.findElement(By.name("filmname"));
	    WebElement petname = driver.findElement(By.name("petname"));
		WebElement director = driver.findElement(By.name("director"));
		WebElement area = driver.findElement(By.name("nation"));
		WebElement editor = driver.findElement(By.name("editor"));
		WebElement language = driver.findElement(By.name("language"));
		WebElement picname = driver.findElement(By.name("picname"));
		
		
		filename.sendKeys("filename");
		petname.sendKeys("petname");
		director.sendKeys("dt");
		area.sendKeys("area");
		editor.sendKeys("ed");
		language.sendKeys("lg");
		picname.sendKeys("D:\\test.jpg");
		
		driver.findElement(By.xpath("//button[@type='submit']")).click();
		Thread.sleep(2000);
	}
}

build.xml

<?xml version="1.0" ?>
<project name ="javacTest" default="run" basedir=".">
	
	 <!-- 定义全局变量 -->
	<property name="dest" value="./build/classes" />
	<property name="testng.output.dir" value="./test-output"/>
	 <!-- 定义类路径 -->
	<path id="classes">
	     <fileset dir="lib" includes="*.jar"/>
		 <pathelement location="${dest}"/>
	</path>
	<taskdef resource="testngtasks" classpath="lib/org.testng_7.jar"/>  
   
    <target name="clean">
        <delete dir="${dest}"/>
    </target>
    <!-- 编译 src目录 -->
    <target name="compile"  depends ="clean">
        <mkdir dir ="${dest}"/>
    	  <javac srcdir="src" destdir="${dest}"  classpathref="classes" includeantruntime="on" encoding="UTF-8" />
    </target>
    <!-- 运行 -->
    <target name="run"  depends ="compile">
     	   	<testng outputdir="${testng.report.dir}" classpathref="classes" >
    	  	 <xmlfileset dir="." includes="testng.xml"/>
    	  	</testng>
    </target>
</project>
testng.xml

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
  
<suite name="Suite1" verbose="1" >
  <test name="t1">
    <classes>
      <class name="antwork.AddMovie"/>
    </classes>
  </test>
</suite>

test.bat

f:cd javawork\antworkcall antpause

实现步骤,写出添加影片的测试类,配置testng.xml,配置build.xml,配置test.bat,设置定时任务

李焕贞

任务已更新