Untitled

 avatar
unknown
python
3 years ago
2.3 kB
6
Indexable
from locust import HttpUser, task
from locust import LoadTestShape


payload = {
	"txtUserId": "DotNet",
	"txtPassword": "DotNet",
}

orderPayload = {
	"listCardType": "Visa",
	"txtCardNumber": "9999%209999%209999%209999",
	"listMonth": "01",
	"listYear": "2002",
	"billAddr%24txtFirstName": "ABC",
	"billAddr%24txtLastName": "XYX",
	"billAddr%24txtAddress1": "901%20San%20Antonio%20Road",
	"billAddr%24txtAddress2": "MS%20UCUP02-206",
	"billAddr%24txtCity": "Palo%20Alto",
	"billAddr%24listState": "Ca",
	"billAddr%24txtZip": "94303",
	"billAddr%24listCountry": "USA",
	"billAddr%24txtPhone": "555-555-55",
	"chkShipBilling": "on",
}

class WebsiteUser(HttpUser):
	host = "http://mspetshop.com"

	def on_start(self):
		self.client.headers.update({'Content-type': 'application/x-www-form-urlencoded'})

	@task
	def get_sign_in(self):
		self.client.get("/MSPetShop/SignIn.aspx", data=payload)

	@task
	def post_sign_it(self):
		self.client.post("/MSPetShop/SignIn.aspx", data=payload)

	@task
	def get_fish_category_page(self):
		self.client.get("/MSPetShop/Category.aspx?categoryId=FISH", data=payload)

	@task
	def get_items_from_category(self):
		self.client.get("/MSPetShop/Items.aspx?productId=FI-FW-02", data=payload)

	@task
	def add_item_to_cart(self):
		self.client.get("/MSPetShop/ShoppingCart.aspx?itemId=EST-20", data=payload)

	@task
	def get_checkout(self):
		self.client.get("/MSPetShop/Checkout.aspx", data=payload)  

	@task
	def get_billing_page(self):
		self.client.get("/MSPetShop/OrderBilling.aspx", data=payload)

	@task
	def post_checkout(self):
		self.client.post("/MSPetShop/OrderBilling.aspx", data=orderPayload)

	@task
	def send_order(self):
		self.client.get("/MSPetShop/OrderProcess.aspx", data=payload)

	@task
	def sign_out(self):
		self.client.get("/MSPetShop/SignOut.aspx", data=payload)




class StagesShape(LoadTestShape):
    stages = [
        {"duration": 60, "users": 50, "spawn_rate": 1},
        {"duration": 120, "users": 50, "spawn_rate": 1}
    ]

    def tick(self):
        run_time = self.get_run_time()

        for stage in self.stages:
            if run_time < stage["duration"]:
                tick_data = (stage["users"], stage["spawn_rate"])
                return tick_data

        return None