BOT error from terminal but working fine in browser

84 views
Skip to first unread message

rajib prasad

unread,
Feb 16, 2022, 12:11:49 PM2/16/22
to oTree help & discussion
I am facing a problem: my last page is coded in a way such that when the game reaches the final round, it will automatically pick a random round and will show payoff from that randomly selected round. When I am manually trying the session, it works fine and showing the desired last page. But
 when I am using bot, it is failing to show the last page give=ing an error like: AssertionError: Bot expects to be on page Payoff but current page is /p/hzt9jyop/grp_contst_bot/MyPage/9. Check your bot code, then create a new session.

my last page code is like the followings:
python code
class Payoff(Page):
@staticmethod
def is_displayed(player: Player):
return player.round_number == C.NUM_ROUNDS

html page code
{{ block content }}
{{ if subsession.round_number == C.NUM_ROUNDS }}
<p>
Round {{ participant.selected_round }} was randomly selected for payment.
Your final payoff is therefore {{ player.payoff_final }}.
</p>
{{ endif }}


and my bot code is like following:(tests.py)

from otree.api import Currency as c, currency_range
from . import *
from otree.api import Bot, SubmissionMustFail
import random

class PlayerBot(Bot):
def play_round(self):
if self.subsession.round_number == 1:
yield Welcome
# yield SubmissionMustFail(MyPage, {"contribution": random.choice(currency_range(0, C.ENDOWMENT,1))})
# yield MyPage, {"contribution": random.choice(currency_range(0, C.ENDOWMENT,1))}
#yield SubmissionMustFail(MyPage, {"contribution": random.randint(0, C.ENDOWMENT+1)})
yield MyPage, {"contribution": random.randint(0, C.ENDOWMENT)}
yield Results
yield Payoff
{{ endblock }}

Can you say what is going wrong in my tests.py code??

rajib prasad

unread,
Feb 16, 2022, 1:49:14 PM2/16/22
to oTree help & discussion
SOLVED:
Since I had is_displayed function, so I had to add if check criteria in tests.py. Now it works fine through terminal. Thanks to Jonas for the clarification to solve the issue.
Note: Since there is a page where I have an is displayed function, so need to repeat the same if check in the test.py. Otherwise the bot tries to interact with a page that is not displayed.

Reply all
Reply to author
Forward
0 new messages