Hello, guys!
I’ve created a customKeyword method for enter in a website and get a “cpf”:
public class buscaNovoCpf {
@Keyword
def coletarCpf(){
WebUI.openBrowser('');
WebUI.maximizeWindow();
WebUI.navigateToUrl('https://www.geradordecpf.org/');
WebUI.delay(2);
def driver = DriverFactory.getWebDriver();
WebElement btnGerarCpf = driver.findElement(By.cssSelector('#btn-gerar-cpf'));
btnGerarCpf.click();
def cpfValue = WebUI.executeJavaScript('return $(".col-sm-8 #numero").val()', []);
println(cpfValue);
}
}
CPF is a personal document here in Brazil and this website provides a fake for testing purposes.
If i want to use the variable “cpfValue” in a test case, how can i access this?
Thanks!
If I’ve understood correctly…
String coletarCpf(){
WebUI.openBrowser('');
WebUI.maximizeWindow();
WebUI.navigateToUrl('https://www.geradordecpf.org/');
WebUI.delay(2);
def driver = DriverFactory.getWebDriver();
WebElement btnGerarCpf = driver.findElement(By.cssSelector('#btn-gerar-cpf'));
btnGerarCpf.click();
def cpfValue = WebUI.executeJavaScript('return $(".col-sm-8 #numero").val()', []);
return cpfValue
}
In your test case…
println(/* The call to your coletarCpf Keyword*/)
Hello, Russ
My idea is something like this:
CustomKeywords.'metodosGenericos.buscaNovoCpf.coletarCpf'();
WebUI.setText(findTestObject('Page_ (4)/input_defaultDocumentValue'), 'cpfValue');
Call the method that will return the cpfValue and “paste” him at the right field on the form.
Try this, Mateus :
String cpf = CustomKeywords.'metodosGenericos.buscaNovoCpf.coletarCpf'()
WebUI.setText(findTestObject('Page_ (4)/input_defaultDocumentValue'), cpf)
But make sure you change coletarCpf to type String (see my last post).
1 Like
Thank you so much, Russ, it worked fine for me!!
Best regards, bro!
You’re welcome. And thanks for the BA B)