Java 如何通过动态电子邮件生成测试电子邮件验证流程并自动获取电子邮件数据?

Java 如何通过动态电子邮件生成测试电子邮件验证流程并自动获取电子邮件数据?,java,selenium-webdriver,qa,browser-automation,Java,Selenium Webdriver,Qa,Browser Automation,我面临注册和登录流程的问题,需要生成电子邮件并获取令牌进行验证。我需要一个服务,允许用户生成n个一次性电子邮件与电子邮件数据访问,可以自毁最多24小时。任何人都可以分享SeleniumJava自动化中使用的服务代码吗 QA团队将这些任务留给手动测试,而不是为这些场景编写自动化测试\ 但是,所有来自电子邮件的通信都可以通过一次性电子邮件服务实现自动化。本文将描述如何使用Nightwatch.js(Node)在自动化套件中使用此服务 您也可以使用此代码来自动化这些事情: 2。在公共函数类中写下ge

我面临注册和登录流程的问题,需要生成电子邮件并获取令牌进行验证。我需要一个服务,允许用户生成n个一次性电子邮件与电子邮件数据访问,可以自毁最多24小时。任何人都可以分享SeleniumJava自动化中使用的服务代码吗

QA团队将这些任务留给手动测试,而不是为这些场景编写自动化测试\

但是,所有来自电子邮件的通信都可以通过一次性电子邮件服务实现自动化。本文将描述如何使用Nightwatch.js(Node)在自动化套件中使用此服务

您也可以使用此代码来自动化这些事情:

2。在公共函数类中写下getEmail的逻辑,并在pom.xml文件中添加依赖项:


<dependency>



<groupId>com.mashape.unirest</groupId>



<artifactId>unirest-java</artifactId>



<version>1.4.9</version>



</dependency>


如果您在本地基础设施中部署测试中的应用程序,您可以使用服务器完全控制您的电子邮件流量



import org.apcahe.commons.lang3.RandomStringUtils;



public class mail7{



private static final String EMAIL-DOMAIN = ‘mail.io’;

private static final String EMAIL_APIKEY = ‘mail7_api_key’;

private static final String EMAIL_APISecret = ‘mail7_api_secret’;

private String emailid;



public usernameGenerator(){



String username = RandomStringUtils.randomAlphanumeric(8).toLowerCase();

System.out. println(“Random Username is ” + username);

return username;

}



public getInbox(String username){



HttpResponse <String> httpResponse = Unirest.get(“"https://api.mail7.io/inbox?apikey=" + EMAIL_APIKEY + "&apisecret=" + EMAIL_APISecret + "&to=" + username”)

.asString();

System.out.println( httpResponse.getHeaders().get("Content-Type"));

System.out.println(httpResponse.getBody());

return httpResponse.getBody();



}


import org.openqa.selenium.*;

import org.openqa.selenium.firefox.FirefoxDriver;

import java.util.List;

import java.util.concurrent.TimeUnit;



public class TestEmail throws IOException, UnirestException

{



public static void main(String[] args) {



//create a Selenium WebDriver instance

System.setProperty("webdriver.gecko.driver","dir_path\\geckodriver.exe");

WebDriver driver = new FirefoxDriver();



//launch the Firefox browser and navigate to the website

driver.get(“YOUR_TEST_URL");



//puts an implicit wait for 10 seconds before throwing exceptions

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);



//locate the email field

WebElement email = driver.findElement(By.xpath("//input[@type='email']"));



// create a random email address



String username = usernameGenerator();



String emailID = username.concat(“@”+EMAIL_DOMIAN);



//set the field's value

email.sendKeys(emailID);



//locate the password field

WebElement password = driver.findElement(By.xpath("//input[@type='password']"));



//set the password's value

password.sendKeys("password");



//locate and click the submit button

driver.findElement(By.xpath("//input[@type='submit']")).click();



//check if the mail has been received or not

String response = getInbo(username );



if(response.isEmpty()) {

System.out.println("Test not passed");

}else {

System.out.println("Test passed");

}



//close the Firefox browser.

driver.close();

}

}

}

}