selenium weDriver sample on java

package seleniumSmpl;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;

import org.junit.Test;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.ie.*;

import java.io.File;
import java.util.concurrent.TimeUnit;


public class TtestSelForEdge {
	
	private WebDriver webDriver;
	
    @Before
    public void createDriver() {
    	//webDriver for Edge
    	//ver 83.0.478.61
    	EdgeOptions op = new EdgeOptions();
    	// headless mode
    	//op.addArguments("--headless");
    	
    	File file = new File("/Users/tk/tera_batch/wk/seleniumSmpl/bin/msedgedriver");
    	System.setProperty("webdriver.edge.driver", file.getAbsolutePath());
        //headless mode
        //webDriver = new EdgeDriver(op);
    	webDriver = new EdgeDriver();
        
    }

    @After
    public void quitDriver() {
        webDriver.close();
    }

	@Test
	public void test() throws Exception {
		
		
	//sample page
        webDriver.get("http://localhost:9000/tutorial-thin-nouveaux/");

        webDriver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
        
        System.out.println(webDriver.getCurrentUrl());
        System.out.println(webDriver.getTitle());
        
        //ログオン画面へのリンククリック
		WebElement wb = webDriver.findElement(By.linkText("ログオン画面へ"));
		JavascriptExecutor executor = (JavascriptExecutor)webDriver;
		executor.executeScript("arguments[0].click();", wb);
        
        
        webDriver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
        System.out.println(webDriver.getCurrentUrl());
        System.out.println(webDriver.getTitle());
        
        //ユーザIDを入力して「ログオン」ボタンクリック
        webDriver.findElement(By.name("userId")).sendKeys("031");
        webDriver.findElement(By.xpath("//input[@type='submit' and @value='ログオン']"))
        	.sendKeys(Keys.ENTER);
        
        Thread.sleep(2000);
        System.out.println(webDriver.getCurrentUrl());
        System.out.println(webDriver.getTitle());
        //「登録」ボタンクリック
        //webDriver.findElement(By.name("forward_insert")).sendKeys(Keys.ENTER);
        //アコーディオンメニューのリンククリック
        WebElement wb_ext =webDriver.findElement(By.linkText("menu"));
        JavascriptExecutor executor2 = (JavascriptExecutor)webDriver;
		executor2.executeScript("arguments[0].click();", wb_ext);

        Thread.sleep(2000);
        System.out.println(webDriver.getCurrentUrl());
        System.out.println(webDriver.getTitle());
        
        //「登録」画面入力、「登録」ボタンクリック
        webDriver.findElement(By.name("id")).sendKeys("600");
        webDriver.findElement(By.name("name")).sendKeys("sucessuseri");
        webDriver.findElement(By.name("age")).sendKeys("10");
        webDriver.findElement(By.name("birth")).sendKeys("2010/06/20");
        webDriver.findElement(By.xpath("//input[@type='submit' and @value='登録']"))
    	.sendKeys(Keys.ENTER);
        Thread.sleep(5000);
        System.out.println(webDriver.getCurrentUrl());
        System.out.println(webDriver.getTitle());
        assertEquals("結果画面",webDriver.getTitle());


	}

}

jenkins on Mac OS X

homebrewでインストールした際、初回起動時にanonymous以外のユーザが

未作成にも関わらず、ログインを求められる。

 

ネット上にはパスワードファイルを確認するように書かれているが、そもそも

ユーザアカウントが一つもないのでパスワードファイルなどない。

その際の手順メモ。

 

1)/Users/[ユーザ]/.jenkins/ ディレクトリ直下の config.xml

   の <userSecurity>true</userSecurity> を、falseに変更

2)jenkins再起動

brew services restart jenkins

3)http://localhost:8080 から匿名アクセスできるようになるので、

  必要なユーザ、権限設定する

参考:

stackoverflow.com

log4j to console

log4j.rootCategory=INFO, consoleLog

 

log4j.category.jp.terasoluna=DEBUG

log4j.category.org.springframework=INFO

log4j.category.org.apache.struts=INFO

 

log4j.appender.consoleLog=org.apache.log4j.ConsoleAppender

log4j.appender.consoleLog.Target=System.out

log4j.appender.consoleLog.layout=org.apache.log4j.PatternLayout

log4j.appender.consoleLog.layout.ConversionPattern=[%d{yyyy/MM/dd HH:mm:ss}][%p][%c{1}] %m%n

using Set not to duplicate values

sample code below

 

package homeWork;

 

import java.util.ArrayList;

import java.util.HashMap;

import java.util.HashSet;

import java.util.List;

import java.util.Map;

import java.util.Set;

 

public class distinctSample2 {

 

public static void main(String[] args) {

 

Set<Map<String,Object>>  countries = new HashSet<Map<String, Object>>();

 

 

Map<String, Object> country;

 

country = new HashMap<String, Object>();

country.put( "collectYM",   "201801" );

country.put( "population", 1000 );

countries.add( country );

 

country = new HashMap<String, Object>();

country.put( "collectYM",   "201802" );

country.put( "population", 1200 );

countries.add( country );

 

country = new HashMap<String, Object>();

country.put( "collectYM",   "201804" );

country.put( "population", 800 );

countries.add( country );

 

country = new HashMap<String, Object>();

country.put( "collectYM",   "201803" );

country.put( "population", 1000 );

countries.add( country );

 

country = new HashMap<String, Object>();

country.put( "collectYM",   "201803" );

country.put( "population", 1000 );

countries.add( country );

 

country = new HashMap<String, Object>();

country.put( "collectYM",   "201804" );

country.put( "population", 800 );

countries.add( country );

 

countries.stream().forEach(System.out::println);

 

List<Map<String, Object>> Listcountries=new ArrayList<Map<String, Object>>();

 

Listcountries.addAll(countries);

 

System.out.println("Set to List");

Listcountries.stream().forEach(System.out::println);

 

}

 

}

 

result :

f:id:annazola:20191018020915p:plain

 

another way(Set to List)

List<Map<String, Object>> Listcountries2=new ArrayList<Map<String, Object>>(countries);