Generate random emails
You need random string generator. This answer I stole from here.
protected String getSaltString() {
String SALTCHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
StringBuilder salt = new StringBuilder();
Random rnd = new Random();
while (salt.length() < 10) { // length of the random string.
int index = (int) (rnd.nextFloat() * SALTCHARS.length());
salt.append(SALTCHARS.charAt(index));
}
String saltStr = salt.toString();
return saltStr;
}
Call it as getSaltString()+"@gmail.com"
in you code
How do I generate random email addresses in test.check?
When I run this script:
clojure -Sdeps '{:deps {org.clojure/test.check {:mvn/version "1.1.0"}}}' /dev/stdin <<EOF
(require '[clojure.test.check.generators :as gen])
(def gen-email
(gen/fmap (fn [[s1 s2]] (format "%s@%s.com" s1 s2))
(gen/tuple gen/string-alphanumeric
gen/string-alphanumeric)))
(run! prn (gen/sample gen-email))
EOF
I get this output:
"@.com"
"@.com"
"9p@VH.com"
"x1@Ws.com"
"23mF@93.com"
"b40@14.com"
"v0n@5Wskg.com"
"mNo@R85LuM.com"
"@.com"
"8Z84B9U0@f9QSJgM.com"
How to generate unique random emails with nodemailer
After looking the source code of nodemailer
I found there is a cache you can disabled by ETHEREAL_CACHE=false
. This generates new emails every time.
Generate random email address and hide form field
You can track whether the value is generated with a data
attribute (ex: <input ... data-generated="1" />
)
When generated you can set the input to disabled
so that the user cannot change the value (ex: <input ... disabled />
)
so the generated state for the input would look like:
<input type="text" id="email-field" name="email"
value="987239478@dummyaddress.com" data-generated="1" disabled>
clicking the button again would reset the input back to
<input type="text" id="email-field" name="email" value="">
jsfiddle
$('#random-hold').on('click','.generate-random', () => {
let email = $('#email-field');
if (email.data('generated') === '1') {
email.val('');
email.removeData('generated');
email.removeAttr('disabled');
} else {
email.val(Math.floor(Math.random() * 1000000000) + "@dummyaddress.com");
email.data('generated', '1');
email.attr('disabled', 'disabled');
}
});
Alternatively, you might consider doing all this without jQuery, using vanilla Javascript/ES6.
document.querySelector('.generate-random').addEventListener('click', () => {
let email = document.myForm.email;
if (email.getAttribute('data-generated') === '1') {
email.value = '';
email.removeAttribute('data-generated');
email.removeAttribute('disabled');
} else {
email.value = Math.floor(Math.random() * 1000000000) + "@dummyaddress.com";
email.setAttribute('data-generated', '1');
email.setAttribute('disabled', 'disabled');
}
});
After generating a random email address, I want to be able to use that same generated email address again
It's very simple. You just need to save the randomly generated email address in a variable and then reuse it again & again whenever you want. All you have to do is:
var randomEmail= chars[Math.floor(Math.random()*26)]
+ Math.random().toString(36).substring(2,11)
+ '@random.com';
return $browser.findElement($driver.By.id("brokers_register_main_broker_username"))
.sendKeys(randomEmail);
Generating random email addresses (more efficient append)
You can generate your three-digit number at once, instead of generating three separate digits. Remember to format the number, so when it generates value of 0, you will get "jhumphr000" instead of "jhumphr0"
Random random = new Random();
int number = random.nextInt(1000);
String randoms = String.format("%03d", number);
Related Topics
Generate Bank Account Number With Random
How to Check Whether an Integer Is Null or Zero in Java
How to Send Date in Rest API in Post Method
How to Convert a Kotlin Source File to a Java Source File
How to Pass List in Postman in Get Request and Get in Getmapping
Is There an Invisible Character That Is Not Regarded as Whitespace
How to Replace Multiple Words in a Single String in Java
How to Make Program to Continue Running After Exception
How to Check Type of Variable in Java
Consider Defining a Bean of Type in Your Configuration
403 Forbidden When I Try to Post to My Spring API
Is There a Java Setting for Disabling Certificate Validation
How to Activate a Function When Some Variable Changes
How to Update Each Element in a List in Java 8 Using Stream API
Spring Boot - How to Get Running Port and Ip Address