com.xyxy.platform.examples.showcase.functional.account.UserManagerFT.java Source code

Java tutorial

Introduction

Here is the source code for com.xyxy.platform.examples.showcase.functional.account.UserManagerFT.java

Source

/*******************************************************************************
 * Copyright (c) 2005, 2014
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.xyxy.platform.examples.showcase.functional.account;

import static org.assertj.core.api.Assertions.*;

import com.xyxy.platform.examples.showcase.functional.BaseSeleniumTestCase;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import com.xyxy.platform.modules.core.test.category.Smoke;

/**
 * ?.
 * 
 *
 */
public class UserManagerFT extends BaseSeleniumTestCase {

    @Test
    @Category(Smoke.class)
    public void list() {
        s.open("/");
        s.click(By.linkText("???"));
        loginAsAdminIfNecessary();
        s.waitForTitleContains("?");
        WebElement table = s.findElement(By.id("contentTable"));
        assertThat(s.getTable(table, 0, 1)).isEqualTo("? ");
    }

    @Test
    @Category(Smoke.class)
    public void editUser() {
        s.open("/");
        s.click(By.linkText("???"));
        loginAsAdminIfNecessary();

        s.click(By.id("editLink-user"));

        // ??
        s.type(By.name("name"), "user_foo");
        s.check(By.id("status2"));
        s.click(By.id("submit_btn"));

        // ??, ?
        s.click(By.id("editLink-user"));
        assertThat(s.getValue(By.name("name"))).isEqualTo("user_foo");
        assertThat(s.isChecked(By.id("status2"))).isTrue();

        // ??
        s.type(By.name("name"), "user");
        s.check(By.id("status1"));
        s.click(By.id("submit_btn"));
    }

    private void loginAsAdminIfNecessary() {
        // ????
        if (s.getTitle().contains("")) {
            s.type(By.name("username"), "admin");
            s.type(By.name("password"), "admin");
            s.click(By.id("submit_btn"));
        }
    }
}