1
votes

I am using Gatling Tool. Initially, I have to login to service. I am trying to login on "login.salesforce.com".

This is my scala code. I am unable to login. Guide me where I am doing wrong.

package default

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import io.gatling.core.Predef._


class requestUser extends Simulation {	

	
	val httpProtocol = http.baseURL("http://login.salesforce.com")
	
	val headers_1 = Map(
		"Accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
		"Accept-Encoding" -> "gzip, deflate",
		"Cache-Control" -> "no-cache",
		"Origin" -> "https://testingapp-dev-ed.my.salesforce.com",
		"Pragma" -> "no-cache",
		"Upgrade-Insecure-Requests" -> "1")

	val headers_2 = Map(
		"Accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
		"Cache-Control" -> "no-cache",
		"Pragma" -> "no-cache",
		"Upgrade-Insecure-Requests" -> "1")


	val Test = exec(http("request 1")
					.get("/?stbdtimeout=1&login_hint=opareshbhai%40steelbrick.com")
					.headers(headers_2))
			  .exec(http("Login")
						.post("/")
						.headers(headers_1)
						.formParam("pqs", "%3Fstbdtimeout%3D1%26login_hint%3Dabcd%2540steelbrick.com")
						.formParam("un", "abcd%40gmail.com")
						.formParam("width", "1536")
						.formParam("height", "960")
						.formParam("hasRememberUn", "true")
						.formParam("startURL", "")
						.formParam("loginURL", "")
						.formParam("loginType", "")
						.formParam("useSecure", "true")
						.formParam("local", "")
						.formParam("lt", "standard")
						.formParam("qs", "r%3Dhttps%253A%252F%252Flogin.salesforce.com%252F")
						.formParam("locale", "")
						.formParam("oauth_token", "")
						.formParam("oauth_callback", "")
						.formParam("login", "")
						.formParam("serverid", "")
						.formParam("display", "page")
						.formParam("username", "abcd%40gmail.com")
						.formParam("ExtraLog", "%255B%257B%2522width%2522%3A1536%257D%2C%257B%2522height%2522%3A960%257D%2C%257B%2522language%2522%3A%2522en-US%2522%257D%2C%257B%2522offset%2522%3A-5.5%257D%2C%257B%2522scripts%2522%3A%255B%257B%2522size%2522%3A249%2C%2522summary%2522%3A%2522if%2520%28self%2520%3D%3D%2520top%29%2520%257Bdocument.documentElement.style.v%2522%257D%2C%257B%2522size%2522%3A568%2C%2522summary%2522%3A%2522var%2520SFDCSessionVars%3D%257B%255C%2522server%255C%2522%3A%255C%2522https%3A%2F%2Flogin.sales%2522%257D%2C%257B%2522url%2522%3A%2522https%3A%2F%2Ftestingapp-dev-ed.my.salesforce.com%2Fjslibrary%2FSfdcSessionBase198.js%2522%257D%2C%257B%2522url%2522%3A%2522https%3A%2F%2Ftestingapp-dev-ed.my.salesforce.com%2Fjslibrary%2FLoginHint198.js%2522%257D%2C%257B%2522size%2522%3A26%2C%2522summary%2522%3A%2522LoginHint.hideLoginForm%28%29%3B%2522%257D%2C%257B%2522size%2522%3A36%2C%2522summary%2522%3A%2522LoginHint.getSavedIdentities%28false%29%3B%2522%257D%2C%257B%2522url%2522%3A%2522https%3A%2F%2Ftestingapp-dev-ed.my.salesforce.com%2Fjslibrary%2Fbaselogin2.js%2522%257D%2C%257B%2522url%2522%3A%2522https%3A%2F%2Ftestingapp-dev-ed.my.salesforce.com%2Fjslibrary%2FLoginMarketingSurveyResponse.js%2522%257D%2C%257B%2522size%2522%3A397%2C%2522summary%2522%3A%2522function%2520handleLogin%28%29%257Bdocument.login.un.value%3Ddoc%2522%257D%255D%257D%2C%257B%2522scriptCount%2522%3A9%257D%2C%257B%2522iframes%2522%3A%255B%2522https%3A%2F%2Fc.salesforce.com%2Flogin-messages%2Fpromos.html%3Fr%3Dhttps%25253A%25252F%25252Flogin.salesforce.com%25252F%2522%2C%2522https%3A%2F%2Flogin.salesforce.com%2Flogin%2Fsessionserver190.html%2522%255D%257D%2C%257B%2522iframeCount%2522%3A2%257D%255D")
						.formParam("pw", "***********")
						.formParam("Login", "Log+In")
						.check(status.is(200), status.not(401))
					)
		   		 		.pause(5)

		   		 .exec(http("set")
							.get("/setup/forcecomHomepage.apexp?setupid=ForceCom")
							.headers(headers_2)
							.check(currentLocation.is("https://google.com"))
							
						)
				var scn = scenario("scn").exec(Test)

	setUp(
		scn.inject(atOnceUsers(1))
		).protocols(httpProtocol)

} 

& This is my log file:

Simulation default.requestUser started...

================================================================================

2016-04-04 12:36:39                                           0s elapsed
---- scn -----------------------------------------------------------------------

[                                                                          ]  0%

          waiting: 1      / active: 0      / done:0
---- Requests ------------------------------------------------------------------

> Global                                                   (OK=0      KO=0     )


================================================================================



================================================================================

2016-04-04 12:36:44                                           5s elapsed
---- scn -----------------------------------------------------------------------

[--------------------------------------------------------------------------]  0%

          waiting: 0      / active: 1      / done:0
---- Requests ------------------------------------------------------------------

> Global                                                   (OK=4      KO=0     )

> request 1                                                (OK=1      KO=0     )

> request 1 Redirect 1                                     (OK=1      KO=0     )

> Login                                                    (OK=1      KO=0     )

> Login Redirect 1                                         (OK=1      KO=0     )

================================================================================


12:36:48.638 [WARN ] i.g.h.a.AsyncHandlerActor - Request 'set' failed: currentLo
cation.find.is(https://google.com), but actually found http://login.salesforce.c
om/setup/forcecomHomepage.apexp?setupid=ForceCom

================================================================================

2016-04-04 12:36:48                                           9s elapsed
---- scn -----------------------------------------------------------------------

[##########################################################################]100%

          waiting: 0      / active: 0      / done:1
---- Requests ------------------------------------------------------------------

> Global                                                   (OK=4      KO=1     )

> request 1                                                (OK=1      KO=0     )

> request 1 Redirect 1                                     (OK=1      KO=0     )

> Login                                                    (OK=1      KO=0     )

> Login Redirect 1                                         (OK=1      KO=0     )

> set                                                      (OK=0      KO=1     )

---- Errors --------------------------------------------------------------------

> currentLocation.find.is(https://google.com), but actually foun      1 (100.0%)

d http://login.salesforce.com/setup/forcecomHomepage.apexp?set...
================================================================================


Simulation finished
Parsing log file(s)...
Parsing log file(s) done
Generating reports...

================================================================================

---- Global Information --------------------------------------------------------

> request count                                          5 (OK=4      KO=1     )

> min response time                                    347 (OK=356    KO=347   )

> max response time                                   2331 (OK=2331   KO=347   )

> mean response time                                   877 (OK=1009   KO=347   )

> std deviation                                        758 (OK=794    KO=0     )

> response time 50th percentile                        421 (OK=676    KO=347   )

> response time 75th percentile                        931 (OK=1281   KO=347   )

> mean requests/sec                                  0.525 (OK=0.42   KO=0.105 )

---- Response Time Distribution ------------------------------------------------

> t < 800 ms                                             2 ( 40%)
> 800 ms < t < 1200 ms                                   1 ( 20%)
> t > 1200 ms                                            1 ( 20%)
> failed                                                 1 ( 20%)
---- Errors --------------------------------------------------------------------

> currentLocation.find.is(https://google.com), but actually foun      1 (100.0%)

d http://login.salesforce.com/setup/forcecomHomepage.apexp?set...
================================================================================
1
Have you tried using Assertions API in Gatling to assert the response body of login request. - TestingWithArif
No. I haven't. Can you tell me what changes are require? - Maharshi
JMeter has builtin assertions elements in it which I use to achieve this objective. You can look into Gatling documentation to see if they provide similar support .. gatling.io/docs/2.0.0-RC2/general/assertions.html - TestingWithArif
Thanks. But I guess -Gatling assertions functionality is limited to response time & failed request. - Maharshi

1 Answers

1
votes

why are you expecting to login "http://www.google.com".That's why your not able to login salesforce and getting an error log

"currentLocation.find.is(https://google.com), but actually found http://login.salesforce.com/setup/forcecomHomepage.apexp?".

Rearrange your code like this and I hope this will work for you

.exec(http("set") .get("/setup/forcecomHomepage.apexp?setupid=ForceCom") .headers(headers_2) )