2014-11-20 12 views
16

Desidero ottenere la data e l'ora correnti come la data di esempio: 11/10/2014 e l'ora 8:30 o 18:00 e passarla come parametri al mio test Jmeter. Qualcuno può aiutarmi a farlo.Jmeter - ottenere la data e l'ora correnti

+0

se hai posto questa domanda qualche anno fa avrei installato jmeter e avrei risposto a questo. Ma qualcosa lungo questo dovresti fare. 1. Creare un processore beanshell e inserire parte del codice java 'new Date()' e memorizzarlo in una variabile, e riutilizzare quella variabile nel test. – ant

+0

Ho provato. Non ho molta familiarità con java ma ho provato $ {__ BeanShell (nuovo java.text.SimpleDateFormat ("MM/gg/aaaa HH: mm: ss"). Format (new Date()))}. Mi viene un errore "jmeter.util.BeanShellInterpreter: Errore durante il richiamo del metodo bsh: eval \t Nel file: valutazione inline di: '' 20/11/2014 09:25:34; '' Incontrato "0" alla riga 1, colonna 12. ". – user3920295

risposta

39

Utilizzare la funzione __time:

  • $ {__ tempo (dd/MM/yyyy,)}

  • $ {__ tempo (hh: mm a,)}

Dal momento che JMeter 3.3, ci sono due nuove funzioni che consentono di calcolare un'ora:

__timeShift

"The timeShift function returns a date in the given format with the specified amount of seconds, minutes, hours, days or months added" and 

__RandomDate

"The RandomDate function returns a random date that lies between the given start date and end date values." 
+0

Ha funzionato !!! Grazie – user3920295

+0

C'è un modo per aggiungere un paio d'ore a questo valore per impostare il timestamp in futuro? – tester

+1

Per modificare la data, potresti provare a utilizzare __javascript, ad esempio, per ottenere un timestamp di 6 ore in futuro: $ {__javaScript (new Date (new Date(). setHours (new Date(). getHours() + 6)). toISOString())} – Sybrand

15

sembra essere il SimpleDateFormat java: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

qui ci sono alcuni test che ho fatto circa 11:30 pm del 20 Maggio 2015

${__time(dd-mmm-yyyy HHmmss)} 20-032-2015 233224 
${__time(d-MMM-yyyy hhmmss)} 20-May-2015 113224 
${__time(dd-m-yyyy hhmmss)} 20-32-2015 113224 
${__time(D-M-yyyy hhmmss)} 140-5-2015 113224 
${__time(DD-MM-yyyy)}   140-05-2015 
+1

C'è un modo per aggiungere un paio di ore a questo valore per impostare la data e l'ora in futuro? – tester

+0

Non c'è un modo semplice ... ma ci sono due modi difficili: –

+1

1) utilizzare un interprete di beanshell per impostare una data usando java (vedere i commenti sulla domanda originale). 2) imposta il tempo in una o più variabili e usa una serie noiosa di funzioni jMeter (intNum e split) per generare la stringa temporale desiderata. –

9

JMeter utilizza java SimpleDateFormat

Per UTC con l'utilizzo fuso orario questo

${__time(yyyy-MM-dd'T'hh:mm:ssX)} 
+1

C'è un modo per aggiungere un paio di ore a questo valore per impostare la data e l'ora in futuro? – tester

5

Usa ${__time(yyyy-MM-dd'T'hh:mm:ss)} per convertire il tempo in un particolare timeformat. Qui ci sono altri formati che è possibile utilizzare:

yyyy/MM/dd HH:mm:ss.SSS 
yyyy/MM/dd HH:mm:ss 
yyyy-MM-dd HH:mm:ss.SSS 
yyyy-MM-dd HH:mm:ss 
MM/dd/yy HH:mm:ss 

È possibile utilizzare il carattere Z per ottenere millisecondi troppo. Per esempio:

yyyy/MM/dd HH:mm:ssZ => 2017-01-25T10:29:00-0700 
yyyy/MM/dd HH:mm:ss.SSS'Z' => 2017-01-25T10:28:49.549Z 

maggior parte del tempo yyyy/MM/dd HH:mm:ss.SSS'Z' è richiesto in alcune API. È meglio sapere come convertire il tempo in questo formato.

2

In realtà, per UTC ho utilizzato Z anziché X, ad es.

${__time(yyyy-MM-dd'T'hh:mm:ssZ)} 

che mi ha dato:

2017-09-14T09:24:54-0400 
1

Utilizzare questo formato: $ {__ tempo (AAAA-MM-dd'T'hh: mm: ss.SS'Z ')}

Che ti darà: 2018-01-16T08: 32: 28.75Z

Problemi correlati