Minecraft Bukkit Server - minecraft

I have created my own Craft Bukkit Minecraft server, and have everything almost set up but have run into a problem. You see, I wish for the server to automatically say something like this every 45 seconds or so:
[Server] Remember to follow the rules! (ETC.)
But I am not sure how to do it. I think I'll require a script, but I have no idea how I'd go about writing it.
Thanks for any help.

If you are looking to make your own plugin you can do a scheduler task every X time and Bukkit.broadcastMessage.
Example:
#Override
public void onEnable() {
new BukkitRunnable() {
#Override
public void run() {
Bukkit.broadcastMessage("[Server] This is the message.");
}
}.runTaskTimer(this, 20, 20*60*10); // 20*60*10 = 10 minutes
}
But if you want a already coded plugin you can download it from spigotmc.org
https://www.spigotmc.org/search/31904533/?q=automessage&t=resource_update&o=relevance

Related

How to run more than one test cases using appium?

I am trying to automate Mobile application after successful login I want to log out and run other test cases also.How to do login code at that time??every time I need to login into the application and every time I need to write Desired capability code??
If I have understood your question, You need to have an extra class, where you have a method where you initialize desired capabilities.
For Example ,
class A{
void capabilities()
{
capabilities.setCapability ("unicodeKeyboard","true");
....
....
}
getDiver()
{
driver = new AndroidDriver(new URL(appiumServiceUrl), getCapability());
}
}
now call in test class file,
A a=new A();
this.driver = appInitializer.getDriver();
Hope ,it will help :)

signalr OnDisconnected method

I am trying to implement an app in which I have used signalr to detect the time at which client is disconnected from server..my hub is like this..
I am using version 0.2.0-alpha
[HubName("TrappistHub")]
public class TrappistHub : Hub
{
public override Task OnDisconnected(bool stopCalled)
{
return base.OnDisconnected(stopCalled);
}
public void SendReport(TestAttendees testAttendee)
{
Clients.All.getReport(testAttendee);
}
}
and DisconnectTime is set default. but when I disconnect from from server OnDisconnected method gets hit after 50 secs instead of 30..and when I set the DisconnectTime to 10 secs or 20 secs it is not getting hit at all..but when I refresh the page it is getting hit...I dont understand why..?
The version you are using (i.e. 0.2.0-alpha) is not supported. Use the new version that shipped last week - 1.0.0-alpha1. See the announcement for more details.

Programmatically execute Gatling tests

I want to use something like Cucumber JVM to drive performance tests written for Gatling.
Ideally the Cucumber features would somehow build a scenario dynamically - probably reusing predefined chain objects similar to the method described in the "Advanced Tutorial", e.g.
val scn = scenario("Scenario Name").exec(Search.search("foo"), Browse.browse, Edit.edit("foo", "bar")
I've looked at how the Maven plugin executes the scripts, and I've also seen mention of using an App trait but I can't find any documentation for the later and it strikes me that somebody else will have wanted to do this before...
Can anybody point (a Gatling noob) in the direction of some documentation or example code of how to achieve this?
EDIT 20150515
So to explain a little more:
I have created a trait which is intended to build up a sequence of, I think, ChainBuilders that are triggered by Cucumber steps:
trait GatlingDsl extends ScalaDsl with EN {
private val gatlingActions = new ArrayBuffer[GatlingBehaviour]
def withGatling(action: GatlingBehaviour): Unit = {
gatlingActions += action
}
}
A GatlingBehaviour would look something like:
object Google {
class Home extends GatlingBehaviour {
def execute: ChainBuilder =
exec(http("Google Home")
.get("/")
)
}
class Search extends GatlingBehaviour {...}
class FindResult extends GatlingBehaviour {...}
}
And inside the StepDef class:
class GoogleStepDefinitions extends GatlingDsl {
Given( """^the Google search page is displayed$""") { () =>
println("Loading www.google.com")
withGatling(Home())
}
When( """^I search for the term "(.*)"$""") { (searchTerm: String) =>
println("Searching for '" + searchTerm + "'...")
withGatling(Search(searchTerm))
}
Then( """^"(.*)" appears in the search results$""") { (expectedResult: String) =>
println("Found " + expectedResult)
withGatling(FindResult(expectedResult))
}
}
The idea being that I can then execute the whole sequence of actions via something like:
val scn = Scenario(cucumberScenario).exec(gatlingActions)
setup(scn.inject(atOnceUsers(1)).protocols(httpConf))
and then check the reports or catch an exception if the test fails, e.g. response time too long.
It seems that no matter how I use the 'exec' method it tries to instantly execute it there and then, not waiting for the scenario.
Also I don't know if this is the best approach to take, we'd like to build some reusable blocks for our Gatling tests that can be constructed via Cucumber's Given/When/Then style. Is there a better or already existing approach?
Sadly, it's not currently feasible to have Gatling directly start a Simulation instance.
Not that's it's not technically feasible, but you're just the first person to try to do this.
Currently, Gatling is usually in charge of compiling and can only be passed the name of the class to load, not an instance itself.
You can maybe start by forking io.gatling.app.Gatling and io.gatling.core.runner.Runner, and then provide a PR to support this new behavior. The former is the main entry point, and the latter the one can instanciate and run the simulation.
I recently ran into a similar situation, and did not want to fork gatling. And while this solved my immediate problem, it only partially solves what you are trying to do, but hopefully someone else will find this useful.
There is an alternative. Gatling is written in Java and Scala so you can call Gatling.main directly and pass it the arguments you need to run the Gatling Simulation you want. The problem is, the main explicitly calls System.exit so you have to also use a custom security manager to prevent it from actually exiting.
You need to know two things:
the class (with the full package) of the Simulation you want to run
example: com.package.your.Simulation1
the path where the binaries are compiled.
The code to run a Simulation:
protected void fire(String gatlingGun, String binaries){
SecurityManager sm = System.getSecurityManager();
System.setSecurityManager(new GatlingSecurityManager());
String[] args = {"--simulation", gatlingGun,
"--results-folder", "gatling-results",
"--binaries-folder", binaries};
try {
io.gatling.app.Gatling.main(args);
}catch(SecurityException se){
LOG.debug("gatling test finished.");
}
System.setSecurityManager(sm);
}
The simple security manager i used:
public class GatlingSecurityManager extends SecurityManager {
#Override
public void checkExit(int status){
throw new SecurityException("Tried to exit.");
}
#Override
public void checkPermission(Permission perm) {
return;
}
}
The problem is then getting the information you want out of the simulation after it has been run.

Selenium get value of current implicit wait

I realize that Selenium has a default value for implicit waits, but how do I get this value if I change it? For example:
driver.implicitly_wait( 13 );
How do I later get the 13 value from the driver?
Unfortunately there's no getter for that.
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html
There isn't for explicit waits either.
http://selenium.googlecode.com/svn/trunk/docs/api/java/com/thoughtworks/selenium/Wait.html
I know I'm a couple years late, and #JaneGoodall is not wrong -- there is no built-in function for that. But it's not impossible!
It's not very difficult to create your own versions of the WebDriver interface and browser-specific driver class. And then, you can put whatever code you want into the driver!
Example:
MyDriver.java (specialized version of WebDriver, not quite mandatory but a very good idea):
public interface MyDriver extends WebDriver {
void setWait(int timeout);
int getWait();
}
MyChrome.java (specialized version of ChromeDriver -- works the same for any browser)
public class MyChrome extends ChromeDriver implements MyDriver {
int timeout = 0;
public void setWait(int timeout) {
this.timeout = timeout;
this.manage().timeouts().implicitlyWait(timeout, TimeUnit.SECONDS);
}
public int getWait() {
return timeout;
}
}
And now, to use it, MyProgram.java:
public class MyProgram {
MyDriver driver = new MyChrome();
driver.setWait(10);
assert(driver.getWait() == 10);
}
I hope this is helpful!
For those who came here from google. In 2018 it seems like there is a method to get those timeouts at least in javascript (I know question was about java):
const {implicit, pageLoad, script} = await driver.manage().getTimeouts();
Hope this will help.
TL;DR - This is not a solution to get implicit waits. You cannot get the implicit wait in Java even today, without using a workaround like this.
In 2020, selenium 3.141.59 still does not have a getter for any timeouts. The WebDriver interface has a nested interface Timeouts which does not define any getters. RemoteWebDriver, which is the parent of Chrome and Firefox drivers, implements the WebDriver interface and it does not add a getter for timeouts.
RemoteWebDriver implements WebDriver.Timeouts, but it does not store the value of implicit timeout anywhere, as you can see from the code below.
protected class RemoteTimeouts implements Timeouts {
public Timeouts implicitlyWait(long time, TimeUnit unit) {
execute(DriverCommand.SET_TIMEOUT, ImmutableMap.of(
"implicit", TimeUnit.MILLISECONDS.convert(time, unit)));
return this;
}
public Timeouts setScriptTimeout(long time, TimeUnit unit) {
execute(DriverCommand.SET_TIMEOUT, ImmutableMap.of(
"script", TimeUnit.MILLISECONDS.convert(time, unit)));
return this;
}
public Timeouts pageLoadTimeout(long time, TimeUnit unit) {
execute(DriverCommand.SET_TIMEOUT, ImmutableMap.of(
"pageLoad", TimeUnit.MILLISECONDS.convert(time, unit)));
return this;
}
} // timeouts class.
The execute() method in the RemoteWebDriver takes the wait inside a Map of parameters, but it does not make that map or the wait settings accessible to us via a getter.
protected Response execute(String driverCommand, Map<String, ?> parameters)
//Open the source code to see why you can't make your own getter for implicitWait.
This can print real timeout value (plus calculating time, usually within 100ms):
public void getCurrentWaitTimeout() {
long milliseconds = java.time.ZonedDateTime.now().toInstant().toEpochMilli();
driver.findElements(By.cssSelector(".nonExistingElement"));
milliseconds = java.time.ZonedDateTime.now().toInstant().toEpochMilli() - milliseconds;
log.info("Current waiting timeout is {} milliseconds", milliseconds);
}
So you can always call such a method to be sure you know actual timeout, not the value you tried to set.
For Java version of Selenium, org.seleniumhq.selenium:selenium-api:4.0.0-beta-4
allows you to get the current implicit wait duration:
WebDriver.manage().timeouts().getImplicitWaitTimeout()
With this method, it makes possible to temporarily change the timeout to let's say 1 second and restore it afterwards:
final Duration originalTimeout = driver.manage().timeouts().getImplicitWaitTimeout();
driver.manage().timeouts().implicitlyWait(Duration.of(1, ChronoUnit.SECONDS));
... // do something
// restore the original timeout
driver.manage().timeouts().implicitlyWait(originalTimeout);
Probably, this functionality is present even before selenium-api:4.0.0-beta-4.
I get the defined implicitTimeout with:
driver.manage().timeouts().getImplicitWaitTimeout().getSeconds()
Many years later, in Python, using selenium 4.4.3 you can access the timeouts very easily via simply:
print(driver.timeouts.implicit_wait)
print(driver.timeouts.page_load)
print(driver.timeouts.script)
Note that when I call driver.implicitly_wait(60), it changed the implicit_wait value only.
Also, there is no such function as driver.manage() in Python, as in the Java answers above.

How do I sense if my unit test is a member of an ordered test and, if it is, which position in that ordered test it is at?

Environment:
I have a program - named CSIS - which I need to run a lot of automated tests on in Visual Studio 2010 using C#. I have a series of functions which need to be run in many different orders but which all start and end at the same 'home screen' of CSIS. The tests will either be run on their own as a single CodedUITest (.cs filetype) or as an ordered test (.orderedtest filetype).
Goal:
The goal is to open to the CSIS homepage once no matter which of the unit tests is run first and then, after all CodedUITests are finished, no matter which unit test is last, the automated test will close CSIS. I don't want to create a separate unit test to open CSIS to the homepage and another to close CSIS as this is very inconvenient for testers to use.
Current Solution Development:
UPDATE: The new big question is how do I get '[ClassInitialize]' to work?
Additional Thoughts:
UPDATE: I now just need ClassInitialize to execute code at the beginning and ClassCleanUp to execute code at the end of a test set.
If you would like the actual code let me know.
Research Update:
Because of Izcd's answer I was able to more accurately research the answer to my own question. I've found an answer online to my problem.
Unfortunately, I don't understand how to implement it in my code. I pasted the code as shown below in the 'Code' section of this question and the test runs fine except that it executes the OpenWindow() and CloseWindow() functions after each test instead of around the whole test set. So ultimately the code does nothing new. How do I fix this?
static private UIMap sharedTest = new UIMap();
[ClassInitialize]
static public void ClassInit(TestContext context)
{
Playback.Initialize();
try
{
sharedTest.OpenCustomerKeeper();
}
finally
{
Playback.Cleanup();
}
}
=====================================================================================
Code
namespace CSIS_TEST
{
//a ton of 'using' statements are here
public partial class UIMap
{
#region Class Initializization and Cleanup
static private UIMap sharedTest = new UIMap();
[ClassInitialize]
static public void ClassInit(TestContext context)
{
Playback.Initialize();
try
{
sharedTest.OpenWindow();
}
finally
{
Playback.Cleanup();
}
}
[ClassCleanup]
static public void ClassCleanup()
{
Playback.Initialize();
try
{
sharedTest.CloseWindow();
}
finally
{
Playback.Cleanup();
}
}
#endregion
Microsoft's unit testing framework includes ClassInitialise and ClassCleanUp attributes which can be used to indicate methods that execute functionality before and after a test run.
( http://msdn.microsoft.com/en-us/library/ms182517.aspx )
Rather than try and make the unit tests aware of their position, I would suggest it might be better to embed the opening and closing logic of the home screen within the aforementioned ClassInitialise and ClassCleanUp marked methods.
I figured out the answer after a very long process of asking questions on StackOverflow, Googling, and just screwing around with the code.
The answer is to use AssemblyInitialize and AssemblyCleanup and to write the code for them inside the DatabaseSetup.cs file which should be auto-generated in your project. You should find that there already is a AssemblyInitialize function in here but it is very basic and there is no AssemblyCleanup after it. All you need to do is create a static copy of your UIMap and use it inside the AssemblyInitialize to run your OpenWindow() code.
Copy the format of the AssemblyInitialize function to create an AssemblyCleanup function and add your CloseWindow() function.
Make sure your Open/CloseWindow functions only contains basic code (such as Process.Start/Kill) as any complex variables such as forms have been cleaned up already and won't work.
Here is the code in my DatabaseSetup.cs:
using System.Data;
using System.Data.Common;
using System.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Data.Schema.UnitTesting;
using System.Windows.Input;
using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;
using MouseButtons = System.Windows.Forms.MouseButtons;
namespace CSIS_TEST
{
[TestClass()]
public class DatabaseSetup
{
static private UIMap uIMap = new UIMap();
static int count = 0;
[AssemblyInitialize()]
public static void InitializeAssembly(TestContext ctx)
{
DatabaseTestClass.TestService.DeployDatabaseProject();
DatabaseTestClass.TestService.GenerateData();
if(count < 1)
uIMap.OpenWindow();
count++;
}
[AssemblyCleanup()]
public static void InitializeAssembly()
{
uIMap.CloseWindow();
}
}
}