fearghal O reilly
fearghal O reilly

Reputation: 140

Run method if test doesnt finish

Hi Im having an issue i cant figure out, Im running a test on a betting game and at the start of each test I need to create a new game for the database, i run my tests on this game and then delete it, so the database doesnt get full of new games as i run about 20 tests that require this. However, the issue im finding is that if there is some UI change all of these tests might fail and im stuck with 20 games in the data base as the game.deletegame() hasnt ran and deleted the game. Is there a way i can get this to run if the test doesnt complete?

Here is my code:

public class register_from_pick_screen extends ConditionsWebDriverFactory{

    public static final int TEST_CASE_PASSED_STATUS = 1;
    public static final int TEST_CASE_FAILED_STATUS = 5;


    @Test
    public void register_from_pick()throws Exception{
        CreateGameSD game = new CreateGameSD();
        game.create_Public_Free_to_Play_game_named_with_description(TestGames.test_web_game,TestGames.test_web_game_description);

        GameLobby lobby = new GameLobby();
        lobby.clickElementWithName(TestGames.test_web_game);
        LeaderBoard leaderboard = new LeaderBoard();
        GameId gameid = new GameId();
        gameid.game_id();
        leaderboard.joinGame();
        FixturesScreen fixtures = new FixturesScreen();
        fixtures.four_picks_make();
        fixtures.picks_match_total();
        fixtures.pick_removal_test();
        fixtures.submit_picks();
        Login login = new Login();
        login.select_register_from_login();
        Register register = new Register();
        register.register_in_pick_screen();
        fixtures.submit_picks();
        PickReceipt pick = new PickReceipt();
        pick.your_in_the_game();
        register_from_login_form.addResultForTestCase("16788",TEST_CASE_PASSED_STATUS," ");

        register_from_login_form.addResultForTestCase("17143",TEST_CASE_PASSED_STATUS," ");
        game.delete_game();
    }
}   

Upvotes: 0

Views: 93

Answers (1)

Edward Dan
Edward Dan

Reputation: 134

Not sure if you want to delete the games if they do successfully run, but if you would like the games to be deleted if they fail you could try this:

Create a new boolean variable that is set to true if your game runs and stays false if it does not.

boolean runSuccess = false;

//game code runs here
//at end of game code add line: runSuccess = true;

//if game code fails to run completely
//runSuccess stays false

if (runSuccess = false)
    game.delete_game();  

If you wanted to make the game delete it-self no matter what, just add the game.delete_game() method to the beginning of the code before you open any other games so that it loops into the game.delete_game() no matter what. Add the method in your pick looping menu so it runs every time a game runs.

Upvotes: 1

Related Questions