Appium ToggleWiFi in Simulator Stops the Test - automated-tests

I am trying to run few offline tests in Android based on ToggleWiFi, but but after turning of the WiFi appium is losing server connection. Is there any way to run tests offline in Appium Simulator by toggling Wifi.
Appium ServerLog

Try this helper method way of turning the wifi off. And keep the test execution going as it is. ( Android Only )
static AppiumDriver driver;
public static void wifiOff() throws InterruptedException {
NetworkConnection mobileDriver = (NetworkConnection) driver;
if (mobileDriver.getNetworkConnection() !=
ConnectionType.AIRPLANE_MODE) {
// enabling Airplane mode
mobileDriver.setNetworkConnection(ConnectionType.AIRPLANE_MODE);
}
}

Related

Bluetooth LE Advertisement watcher not receiving on HoloLens 2

Following on from this question, I'm also having trouble getting a Bluetooth watcher to receive advertisements on HoloLens 2. I've run through the example here with no luck running scenario 2 on my laptop and scenario 1 on my HoloLens.
My HoloLens does not appear to be triggering any received events. I've tried restarting the HoloLens and checking for updates. I'm currently running OS build 20346.1403.
Would greatly appreciate any help troubleshooting. I have been able to get the regular BluetoothLE sample to run correctly, however my eventual goal is to get all this to run from within a Unity application and again for some reason the watcher isn't receiving any events with the regular BluetoothLE code from my Unity application.
If anyone has experience with Unity and bluetoothLE examples I'd very much like to learn more about it.
using TMPro;
using UnityEngine;
#if WINDOWS_UWP
using Windows.Devices.Bluetooth.Advertisement;
using System.Runtime.InteropServices.WindowsRuntime;
#endif
public class GPSReceiver : MonoBehaviour
{
public TextMeshProUGUI debugText;
#if WINDOWS_UWP
BluetoothLEAdvertisementWatcher watcher;
#endif
public static ushort BEACON_ID = 1775;
public EventProcessor eventProcessor;
void Awake()
{
#if WINDOWS_UWP
watcher = new BluetoothLEAdvertisementWatcher();
BluetoothLEManufacturerData manufacturerData = new BluetoothLEManufacturerData
{
CompanyId = BEACON_ID
};
watcher.AdvertisementFilter.Advertisement.ManufacturerData.Add(manufacturerData);
watcher.Received += Watcher_Received;
watcher.Start();
debugText.text = "Watcher status: " + watcher.Status.ToString() + " " + watcher.ScanningMode.ToString();
#endif
}
#if WINDOWS_UWP
private async void Watcher_Received(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
{
debugText.text = "received bytes";
ushort identifier = args.Advertisement.ManufacturerData[0].CompanyId;
byte[] data = args.Advertisement.ManufacturerData[0].Data.ToArray();
// Updates to Unity UI don't seem to work nicely from this callback so just store a reference to the data for later processing.
eventProcessor.QueueData(data);
}
#endif
}

How to run Selenium Brave web browser webdriver in c#?

Someone kind can help me with this.
I have a problem and it is that I cannot run Selenium in Brave with visual studio. Can someone help me on the code? What would it be to execute it? Because with the visual studio webdriver automatically running chrome, I want to tell it to run Brave. Thank you
Requirements:
Install Nuget Packages (Selenium.Webdriver, Selenium.Chrome.Webdriver)
private string chromeDriverPath = #"C:\Path\To\chromedriver.exe"; //Path to chromedriver.exe
private string braveBrowserPath = #"C:\Path\To\brave.exe"; //Path to brave.exe
private ChromeOptions chromeOptions; //Default value of chromeOptions is null
private IWebDriver driver; //Default value of driver is null
public void LoadChrome() {
try
{
Environment.SetEnvironmentVariable("webdriver.chrome.driver", chromeDriverPath); //Sets process evnironment
chromeOptions = new ChromeOptions(); //Initialize chromeOptions
chromeOptions.BinaryLocation = braveBrowserPath; //Sets the location of Brave
driver = new ChromeDriver(chromeOptions); //Initialize driver with chromeOptions
driver.Manage().Window.Maximize(); //Set Brave window maximized
driver.Navigate().GoToUrl("https://www.google.com/"); //Loads page Google
} catch (Exception ex) {
Console.WriteLine(ex.Message); //Print any errors to console log
}
}
Selenium seems to be pretty easy to use. You can take a look at their API and Documentation that include usages and examples with C# programming language.
There is also a cheat sheet you can use for reference in case you're too lazy to look up API or Documentation.

How to setup PUB/SUB NetMQ in Xamarin Forms

I have a Windows Services running as a Publisher and I am trying to setup Xamarin Forms as the Subscriber. The code below works just fine in a Console App or LinqPad, but when copied and pasted into Xamarin Forms, the SubscriberSocket just does not respond to messages from the server.
Do you know how to wire this up?
I am using NetMQ v 4.0.0.1
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
Task.Run(() => StartPubSubSocketSubscriber());
}
private void StartPubSubSocketSubscriber()
{
string topic = "TopicA";
using (var subSocket = new SubscriberSocket())
{
subSocket.Options.ReceiveHighWatermark = 1000;
subSocket.Connect("tcp://192.168.30.120:5556");
subSocket.Subscribe(topic);
while (true)
{
string messageTopicReceived = subSocket.ReceiveFrameString();
string messageReceived = subSocket.ReceiveFrameString();
Device.BeginInvokeOnMainThread(() =>
{
label.Text = messageReceived;
});
}
}
}
}
I also tried starting the background thread with Task.Factory.StartNew(() => StartPubSubSocketSubscriber(), TaskCreationOptions.LongRunning); but it is just as unresponsive to messages from the publisher.
Thank you.
PS.: removed subSocket.Connect("tcp://localhost:5556");
The fix for this was a 2 step process:
The SubscriberSocket was incorrectly pointing to localhost. An understandable mistake since the emulator runs on the same machine as the server application. Make sure the Subscriber has the explicit IP address when running on a virtual environment or another device.
The issue with SubscriberSocket not responding was actually on a server. I had set it up with pubSocket.Bind("tcp://localhost:5556");, once I changed it to pubSocket.Bind("tcp://*:5556"); the SubscriberSocket started responding. This is an error in documentation.
The hint to the solution came from the NetMQ github issue tracking:
https://github.com/zeromq/netmq/issues/747

JavaFx in headless mode

Is it possible to run JavaFx in headless mode(in Java 7)? It is being used to generate images on the server but is asking for an X-Server. Does there exist something like java.awt.headless in JavaFx ?(I can't use Xvfb )
Here is how I solved this problem for server-side image geneartion on Ubuntu linux environment with jetty application server. It uses xvfb but only as a "library" - without any additional special actions on server:
apt-get install xvfb
// then on application server start:
export DISPLAY=":99"
start-stop-daemon --start --background --user jetty --exec "/usr/bin/sudo" -- -u jetty /usr/bin/Xvfb :99 -screen 0 1024x768x24
You can see the details of my server-side image generation solution in this SO question.
This is a kind of problem which I encountered while capturing images in Mac OS.
I have solved this issue by using
static {
System.setProperty("java.awt.headless", "false");
}
See for reference : Headless environment error in java.awt.Robot class with MAC OS
Answer by Shreyas Dave didn't work for me anymore. Though I don't know why, here is what I did:
public static void main(String[] args) {
// to avoid
// [JRSAppKitAWT markAppIsDaemon]: Process manager already initialized: can't fully enable headless mode.
System.setProperty("javafx.macosx.embedded", "true");
java.awt.Toolkit.getDefaultToolkit();
// end
launch(args);
}
This was also pointed out here: JavaFX screencapture headless exception on OSX
If you have the source code of the JavaFX application you could also try to use TestFX run the application in a headless mode, to control it and to make screenshots. To run your TestFX application in headless mode you have to start it with the following JVM parameters (to enable Monocle):
-Dtestfx.robot=glass -Dglass.platform=Monocle -Dmonocle.platform=Headless -Dprism.order=sw
Moreover you might need to install Monocle first. See Headless testing with JavaFx and TestFx for more information.
I have an application that can be used interactively (displaying JavaFx dialogs) but also must be able to run non-interactive on a server without display.
Even though no GUI element is used in non-interactive mode, we got
Caused by: java.lang.UnsupportedOperationException: Unable to open DISPLAY
at com.sun.glass.ui.gtk.GtkApplication.<init>(GtkApplication.java:68)
This happens as soon as a class derived from javafx.application.Application is instantiated, which you normally do with your main class.
Here is the way I solved the problem:
I created an additional class GuiAppExecution:
import java.util.List;
import javafx.application.Application;
import javafx.stage.Stage;
/**
* JavaFx launch class for {#link AppExecution}.
*/
public class GuiAppExecution extends Application {
#Override
public void start(Stage stage) throws Exception {
List<String> parameters = getParameters().getRaw();
AppExecution appExecution = new AppExecution();
appExecution.launch(parameters);
}
/**
* Launches the {#link AppExecution} as JavaFx {#link Application}.
*
* #param parameters program parameters
*/
public void launchGui(String[] parameters) {
launch(parameters);
}
}
In the main class AppExecution I created a method
public void launch(List<String> parameters) {
which parses the parameters and launches the application for both interactive and non-interactive execution.
The main method looks like this:
public static void main(String[] parameters) {
List<String> parameterList = Arrays.asList(parameters);
if (parameterList.stream().anyMatch(p -> p.equalsIgnoreCase(BATCH_PARAMETER))) {
AppExecution appExecution = new AppExecution();
appExecution.launch(parameterList);
}
else {
GuiAppExecution guiAppExecution = new GuiAppExecution();
guiAppExecution.launchGui(parameters);
}
}
with
private static final String BATCH_PARAMETER = "-batch";
as the program option that request the non-interactive execution.
Since GuiAppExecution (which is derived from javafx.application.Application) is not instantiated for non-interactive execution, the JavaFx environment is not started.

Behaviour of JerseyTest Grizzly Web Server on Unix

We have created a test suite and in order to run it we are using embedded Grizzly Web Server with JerseyTest framework.
We are extending a custom class from JerseyTest and in its constructor we are creating ApplicationDescriptor and then call superclass setupTestEnvironment() which essentially starts embedded grizzly web server.
Few of our test cases are extending this custom class to start grizzly server directly. However, we are not stopping this embedded server anywhere in the code.
The test cases run fine on windows but on Unix they fail with java.net.BindException port 9998 is in use by another process.
It becomes obvious these tests should fail with similar error on windows too if we are not stopping embedded web server in the code. How they are running fine on windows and failing on unix. Has this something to do with how Unix spawns threads or processes?
P.S. We have also tested whether port 9998 is in use by some other process using netstat -a | grep 9998 but no other process using that port could be found.
i had a similar problem and i did fix it by not using the default port if already used. just add following code to your test case:
#Override
protected int getPort(int defaultPort) {
ServerSocket server = null;
int port = -1;
try {
server = new ServerSocket(defaultPort);
port = server.getLocalPort();
} catch (IOException e) {
// ignore
} finally {
if (server != null) {
try {
server.close();
} catch (IOException e) {
// ignore
}
}
}
if ((port != -1) || (defaultPort == 0)) {
return port;
}
return getPort(0);
}
I had the same problem, when I was writing my integration tests. I didn't get to test on a Windows machine, but on my Unix machine I found the problem was that by default the JerseyTest class utilizes #After on it's tearDown method to close the embedded server. Since I had overridden this method to do clean up on my side, I had to call super.tearDown()
#After
public void tearDown() throws Exception{
super.tearDown();
...
}
After doing this, everything worked as expected.

Resources