New Relic Sythetics scripted browser - verify the login

Hi Experts,
I read through the scripted browser documentation and was able to write a basic login automation as follows. However the main issue I am seeing is that after logging into the URL, even though I pass “empty” username and password, the script still says “Validated” with a green check which i suppose means is that it validated. In my opinion the script should fail saying that script did not pass as the username or password were either empty OR incorrect. How do i do that verification step?

$browser.get("https://mail.yahoo.com").then(function(){
//Find the user name field by specifying its name, then submits a secured username.
return $browser.findElement($driver.By.name("username")).sendKeys("");
}).then(function(){
//Find the password field by specifying its name, then submits a secured password.
return $browser.findElement($driver.By.name("password")).sendKeys("");
}).then(function(){
//Find and click the login button.  
return $browser.findElement($driver.By.xpath("/html/body/div[2]/div/div/div/div[2]/div/ul/li[2]/div/form/div[1]/div[3]/button/span[1]/span")).click();

});

Hi, @asd: I usually wait for the page to load following a successful login, and verify that some element unique to that page is present. You can see an example in this video:

1 Like

You are correct on your understanding here. When you validate a script, the script runs and will display the green check to state that there are no errors within the script. It does not mean that the script has validated the log in, unless you put some check in there. Usually a logged on user name will be on the page or a log our link making it relatively easy to validate.

Thank you for the quick answers. I have another quick question for yall.
So I am trying to hit 2 different websites with different logins however due to the asynchronous nature of Selenium, when it finishes the last step of first website’s verification, it fails with the error saying unable to find username.

$browser.get("https://mail.yahoo.com").then(function(){

return $browser.findElement($driver.By.name("username")).sendKeys("xyz");
}).then(function(){

return $browser.findElement($driver.By.name("password")).sendKeys("xyz123df");
}).then(function(){

return $browser.findElement($driver.By.xpath("/html/body/div[2]/div/div/div/div[2]/div/ul/li[2]/div/form/div[1]/div[3]/button/span[1]/span")).click();

// This is where it errors out

$browser.get("https://mail.google.com").then(function(){

return $browser.findElement($driver.By.name("username")).sendKeys("abc");
}).then(function(){

return $browser.findElement($driver.By.name("password")).sendKeys("abc123dff");
}).then(function(){

return $browser.findElement($driver.By.xpath("/html/body/div[2]/div/div/div/div[2]/div/ul/li[2]/div/form/div[1]/div[3]/button/span[1]/span")).click();

How do I fix this?

Hi, @skyrocker87: (Are you the same person as @asd ? Why two different usernames?)

The page at https://mail.google.com does not have an element with a name of “username”; that’s why the script can’t find it.

Again, I recommend that you watch the video posted above to learn how to write Synthetics scripts.

Hi @philweber I followed the video but get an error finding element. Can you see where I went wrong?


Thanks!

@philweber ever post something and then realize it was your own error? :slight_smile: I pasted the URL in front of an existing https:// as we can see in my screenshot. Couldn’t find the element because it couldn’t resolve the host… thanks for the video!!

2 Likes

@support_omnigo, it happens to the best of us :sweat_smile: Thankfully you figured it out on your own!

1 Like