@Override public void wait(String message, long timeoutInMilliseconds, long intervalInMilliseconds) { try { super.wait(message, timeoutInMilliseconds, intervalInMilliseconds); } catch (Throwable t) { } }
private static void gas(double chance) { if (Random.whole() <= chance) { Wait.milliseconds(322); System.out.print("\n\n"); Burp burp = new Burp(); if (Random.whole() <= .12) gas(1); } }
@SuppressWarnings("unchecked") @Test public void shouldSilentlyCaptureNoSuchWindowExceptions() { final ExpectedCondition<WebElement> condition = mock(ExpectedCondition.class); checking( new Expectations() { { one(condition).apply(mockDriver); will(throwException(new NoSuchWindowException("foo"))); one(condition).apply(mockDriver); will(returnValue(true)); } }); TickingClock clock = new TickingClock(500); Wait<WebDriver> wait = new WebDriverWait(mockDriver, clock, clock, 5, 500); wait.until(condition); }
/** * Types characters and check that output will not change for defined time (queue delay) and when * it actually change, check that it have value of input and that counters are printed right. */ @Test public void testRequestDelay() { Integer[] delays = stringsToInteger.transform(MSG_DELAY_LIST); for (final int delay : delays) { setQueue(delay, false, false); // initiate time borders for the test final long start = currentTime(); final long end = start + 10000; // create a buffer for whole text in input final StringBuffer typedText = new StringBuffer(); // type at least 3 and at most 100 characters and don't exhause // border of 10 sec. for this tests while (typedText.length() <= 3 || (typedText.length() <= 100 && currentTime() < end)) { final String lastText = typedText.toString(); // type char '1-9' like last decimal char of buffer's length typedText.append(Integer.toString(typedText.length() % 10)); selenium.type(LOC_INPUT_TYPED_TEXT, typedText.toString()); final long eventTime = currentTime(); selenium.fireEvent(LOC_INPUT_TYPED_TEXT, Event.KEYUP); // check that text will not change for defined time (delay) Wait.dontFail() .interval(delay / 4) .timeout(delay) .until( new Condition() { public boolean isTrue() { final String actualText = selenium.getText(LOC_OUTPUT_TYPED_TEXT); long currentTime = currentTime(); assertTrue(currentTime >= eventTime + delay || lastText.equals(actualText)); return currentTime >= eventTime + delay; } }); // wait for output actually changes to value of input waitForTextEquals(LOC_OUTPUT_TYPED_TEXT, typedText.toString()); // check that all output counts are right String actualCount = Integer.toString(typedText.length()); assertEquals(actualCount, selenium.getText(LOC_OUTPUT_EVENTS_COUNT)); assertEquals(actualCount, selenium.getText(LOC_OUTPUT_REQUESTS_COUNT)); assertEquals(actualCount, selenium.getText(LOC_OUTPUT_DOM_UPDATES_COUNT)); } } }
public void run() { for (int j = 0; j < 20; j++) butI[j].removeActionListener(this); Wait.manySec(10); if (but.getIcon() == butn.getIcon()) { but.setVisible(false); butn.setVisible(false); } else { but.setIcon(iconOrg); butn.setIcon(iconOrg); } isVisibl(); for (int j = 0; j < 20; j++) butI[j].addActionListener(this); }
@Override public void handleEvent(PersonDepartureEvent event) { try { if (transitDriverIds.contains(event.getPersonId())) return; TravellerChain chain = chains.get(event.getPersonId()); Journey journey; Trip trip; switch (event.getLegMode()) { case TransportMode.walk: // fall through to the next case TransportMode.transit_walk: if (!chain.traveling) { chain.traveling = true; journey = chain.addJourney(); journey.setOrig(network.getLinks().get(event.getLinkId()).getCoord()); journey.setFromAct(chain.getActs().getLast()); journey.setStartTime(event.getTime()); Walk walk = journey.addWalk(); walk.setAccessWalk(true); walk.setStartTime(event.getTime()); walk.setOrig(journey.getOrig()); } else { journey = chain.getJourneys().getLast(); Walk walk = journey.addWalk(); walk.setStartTime(event.getTime()); walk.setOrig(network.getLinks().get(event.getLinkId()).getCoord()); journey.getPossibleTransfer().getWalks().add(walk); } break; case TransportMode.car: chain.inCar = true; journey = chain.addJourney(); journey.setCarJourney(true); journey.setOrig(network.getLinks().get(event.getLinkId()).getCoord()); journey.setFromAct(chain.getActs().getLast()); journey.setStartTime(event.getTime()); trip = journey.addTrip(); trip.setMode("car"); trip.setStartTime(event.getTime()); break; case TransportMode.pt: if (isTransitScenario) { // person waits till they enter the vehicle journey = chain.getJourneys().getLast(); Wait wait = journey.addWait(); if (journey.getWaits().size() == 1) wait.setAccessWait(true); wait.setStartTime(event.getTime()); wait.setCoord(network.getLinks().get(event.getLinkId()).getCoord()); if (!wait.isAccessWait()) { journey.getPossibleTransfer().getWaits().add(wait); } } else { journey = chain.addJourney(); journey.setTeleportJourney(true); journey.setOrig(network.getLinks().get(event.getLinkId()).getCoord()); journey.setFromAct(chain.getActs().getLast()); journey.setStartTime(event.getTime()); journey.setMainmode(event.getLegMode()); trip = journey.addTrip(); trip.setMode(event.getLegMode()); trip.setStartTime(event.getTime()); } break; default: journey = chain.addJourney(); journey.setTeleportJourney(true); journey.setOrig(network.getLinks().get(event.getLinkId()).getCoord()); journey.setFromAct(chain.getActs().getLast()); journey.setStartTime(event.getTime()); journey.setMainmode(event.getLegMode()); trip = journey.addTrip(); trip.setMode(event.getLegMode()); trip.setStartTime(event.getTime()); break; } } catch (Exception e) { System.err.println(e.getStackTrace()); System.err.println(event.toString()); } }
public Drink(Player player, Scenario scenario, boolean World, boolean from_Ahead) { boolean tavern = scenario.environment.tavern, waterskin_specific = Array.subcontainment_case_ignored( Act.input_backup, Array.combine(triggers_subsafe_uncolloquial_specific, new String[] {"inv"})), resupplying = Array.subcontainment_case_ignored( Act.input_backup, triggers_subsafe_uncolloquial_resupplies), resupplying_order = Random.binary(); if (resupplying && resupplying_order) { Eat eat = new Eat(player, scenario, true, World, from_Ahead); } String quench_your_thirst_phrase = Random.text_of(triggers_subsafe_verbs_colloquial) + " your " + Random.text_of(triggers_subsafe_objects_colloquial); if (World || from_Ahead) { if (tavern && (!waterskin_specific || resupplying)) { if (resupplying) extra(player, new int[] {player.water_max - player.water}, tavern); else { Type.delay( Random.text_of(new String[] {"🍶", "🍷"}) + ": You " + Random.text_of(ordering_statements) + Random.text_of(new String[] {"", " at the bar"}) + "."); drink(player, 1, player.quenched, new int[] {0, 1, 1, 2, 2, 3}, tavern, .2); } } else if (Array.subcontainment_case_ignored( Act.input_backup, triggers_subsafe_uncolloquial_ordering) || Array.containment_case_ignored( triggers_nonsubsafe_uncolloquial_ordering, Act.input_backup)) { Type.delay_line( Random.text_of( new String[] {"You are not in a tavern.", "There is no bartender here!"})); } else if ((!waterskin_specific && scenario.environment.water && Random.whole() <= .95) || (scenario.environment.water && resupplying)) { Wait.milliseconds(400); Type.delay( "💧: " + Random.text_of( new String[] { "You find some water available here", "You access the water source here" }) + "."); if (resupplying) extra(player, new int[] {player.water_max - player.water}, tavern); else { if (scenario.environment.snowy) Type.delay_line( "❄: " + Random.text_of( new String[] { "You feel cold.", "That was chilling.", "You shiver.", "That was cold water!" })); drink( player, 1, Random.integer_of(new int[] {player.quenched - 1, player.quenched}), new int[] {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3}, tavern, .1); } } else if (player.water >= 1 && !resupplying) { int drunk = 1; if (Random.whole() <= .8) { drunk = player.quenched - player.wetness; while (drunk > player.water) drunk--; if (drunk == 0) drunk = 1; } else drunk = Random.integer_of(new int[] {1, 1, 1, 1, 1, 2, 2, 2, 3}); player.water -= drunk; Type.delay( "💧: You " + Random.text_of( new String[] { "drink" + Random.text_of( new String[] { "", " " + Random.text_of( new String[] { "some water", "some of your water", "from your waterskin", "some water from your waterskin", "a few sips of water" + Random.text_of( new String[] {"", " from your waterskin"}) }), }), "sip " + Random.text_of( new String[] { "some water", "on some water", "some of your water", "on some of your water", "from your waterskin", "on your waterskin", "some water from your waterskin" }), Random.text_of(triggers_subsafe_colloquial_guzzles) + " " + Random.text_of( new String[] { "some water", "some of your water", "some water from your waterskin" }), quench_your_thirst_phrase }) + "."); drink(player, drunk, drunk, new int[] {}, tavern, .1); } // type a statement explaining why the player cannot drink // else { if (resupplying) Type.delay_line( Random.text_of( new String[] { "There is no drinkable water nearby", "You have no clean water around to fill your waterskin with" }) + "."); else Type.delay_line( "You have no water" + Random.text_of( new String[] { "", " " + Random.text_of(new String[] {"", "available", "left"}) + Random.text_of( new String[] {"", " to " + quench_your_thirst_phrase + " with"}), "in your waterskin, nor is there any good water around", "on hand, and there is nothing here to " + quench_your_thirst_phrase, "with you, and there is no good drinking water here" }) + "."); } } else { if (resupplying) Type.delay_line("You have no time to resupply during combat!"); else { Type.delay_line( "You have no time to " + Random.text_of( new String[] { "drink", Random.text_of(triggers_subsafe_colloquial_guzzles) + " " + Random.text_of(new String[] {"", "any "}) + "water", "take a " + Random.text_of(triggers_subsafe_colloquial_guzzles) + Random.text_of(new String[] {"", " of water"}), quench_your_thirst_phrase, }) + " during combat!"); } } if (resupplying && !resupplying_order) { Eat eat = new Eat(player, scenario, true, World, from_Ahead); } }