【自动化__GUI自动化】__java__Agileone__seniumIDE

一、代码如下

package www.woniu.gui;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class AgileoneAdd {
    private WebDriver driver;
    private String baseUrl;
    private boolean acceptNextAlert = true;
    private StringBuffer verificationErrors = new StringBuffer();

    @Before
    public void setUp() throws Exception {
        System.setProperty("webdriver.firefox.bin", "D:\\Mozilla Firefox_53\\firefox.exe");
        // System.setProperty("webdriver.gcko.driver", "D:\\geckodriver.exe");
        driver = new FirefoxDriver();
        baseUrl = "http://localhost/Agileone/index.php";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Test
    public void testAgileoneAdd() throws Exception {
        driver.get(baseUrl + "/Agileone/");
        driver.findElement(By.id("username")).clear();
        driver.findElement(By.id("username")).sendKeys("admin");
        driver.findElement(By.id("password")).clear();
        driver.findElement(By.id("password")).sendKeys("admin");
        driver.findElement(By.id("login")).click();
        Thread.sleep(2000);
        assertTrue(isElementPresent(By.linkText("※ 公告管理 ※")));
        driver.findElement(By.linkText("※ 需求提案 ※")).click();
        Thread.sleep(2000);
        driver.findElement(By.id("headline")).clear();
        driver.findElement(By.id("headline")).sendKeys("wujianbo35");
        driver.findElement(By.cssSelector("img.ke-common-icon.ke-icon-source")).click();
        driver.findElement(By.cssSelector("textarea.ke-textarea")).clear();
        driver.findElement(By.cssSelector("textarea.ke-textarea")).sendKeys("wujianbo34");
        driver.findElement(By.id("add")).click();
        Thread.sleep(2000);
        assertTrue(driver.findElement(By.id("msg")).getText().matches("^成功啦: 新增数据成功 -> 编号=.*"));
        driver.findElement(By.linkText("注销")).click();
    }

    @After
    public void tearDown() throws Exception {
        try {
            driver.quit();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
            fail(verificationErrorString);
        }
    }

    private boolean isElementPresent(By by) {
        try {
            driver.findElement(by);
            return true;
        } catch (NoSuchElementException e) {
            return false;
        }
    }

    private boolean isAlertPresent() {
        try {
            driver.switchTo().alert();
            return true;
        } catch (NoAlertPresentException e) {
            return false;
        }
    }

    private String closeAlertAndGetItsText() {
        try {
            Alert alert = driver.switchTo().alert();
            String alertText = alert.getText();
            if (acceptNextAlert) {
                alert.accept();
            } else {
                alert.dismiss();
            }
            return alertText;
        } finally {
            acceptNextAlert = true;
        }
    }
}
时间: 2024-10-25 09:04:27

【自动化__GUI自动化】__java__Agileone__seniumIDE的相关文章

【自动化__GUI自动化】__java__案例__java应用程序计算器

一.代码如下 package www.woniu.gui.one; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.J

【自动化__GUI自动化】__java__Windows应用程序识别__计算器

一.代码如下 package www.woniu.gui.one; import java.awt.AWTException; import java.awt.Robot; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.aw

【自动化__GUI自动化】__java__模拟功能操作__猴子测试

一.代码如下 package www.woniu.auto; import java.awt.AWTException; import java.awt.Robot; import java.awt.event.InputEvent; import java.io.IOException; import java.util.Random; public class MonkeyTest { Robot robot= null; public static void main(String[] a

【自动化__GUI自动化】__java__案例__java应用程序计算器__类直接被调用__1个进程

一.代码如下 package www.woniu.gui.one; public class Test__Two { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("开始执行应用程序"); www.woniu.gui.one.MyCalc__Swing.main(new String[1]); } }

【自动化__GUI自动化】__C#__Windows应用程序识别__计算器

一.代码如下 #include <stdio.h> #include <stdlib.h> #include <windows.h> int main(int argc, char *argv[]) { //printf("成功"); //printf("成功"); //printf("成功"); HWND windowHandle, controlHandle; char result[10]; window

【自动化__GUI自动化】__java__模拟功能操作__键盘

一.代码如下 package www.woniu.auto; import java.awt.AWTException; import java.awt.Robot; import java.awt.event.KeyEvent; import java.io.IOException; public class RobotUseage { public static void main(String[] args) { // TODO Auto-generated method stub try

【自动化__GUI自动化】__java__案例__java应用程序计算器__执行测试的代码

一.代码如下 package com.woniuxy.auto; import java.awt.Component; import java.awt.Frame; import java.lang.reflect.Method; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTe

【自动化__GUI自动化】__java__模拟功能操作__鼠标

一.具体代码如下 package www.woniu.auto; import java.awt.AWTException; import java.awt.Robot; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.io.IOException; public class RobotMouse { public static void main(String[] args) { //

【自动化__GUI自动化】__java__案例__类反射

一.代码如下 1.1.被发射类 package www.woniu.gui.one; public class Test { private int age= 30; private String name= "张三"; public int getAge() { return age; } public void setAge(int age) { this.age = age; } private String getName() { return name; } public v