How to make the selected testcript is run in selenium grid - selenium-grid

I need a help.........
I can launch some remote control by using:
ant launch-remote-control
but I dont know how my script connect to hub?
I set up ant, selenium-grid on the same computer.
I have an grid.dll which is written by C# and run through NUnit.
The test data is read from xml file (ValidData.xml)
The example code is below :
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.Xml;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;
namespace Grid
{
public class Class1
{
//User defined
private string strURL = "http://gmail.com/";
private string[] strBrowser = new string[3] { "*iehta", "*firefox", "*safari" };
string hubAddress = "192.168.20.131"; // IP of my computer
// System defined
private ISelenium selenium;
private StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium(hubAddress, 4444, this.strBrowser[1], this.strURL);// do i need to identify browser when I defined it when launching a remote control
selenium.Start();
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
private string[] name;
[Test]
public void LoginPassedTest()
{
try
{
XmlDocument doc = new XmlDocument();
XmlNode docNode;
doc.Load("ValidData.xml");
docNode = doc["TestCase"];
foreach (XmlNode node in docNode)
{
selenium.Open("/");
selenium.WaitForPageToLoad("50000");
selenium.Type("Email", node["username"].InnerText);
selenium.Type("Passwd", node["password"].InnerText);
selenium.Click("signIn");
selenium.WaitForPageToLoad("100000");
name = (selenium.GetText("//div[#id='guser']/nobr/b").Split('#'));
try
{
Assert.AreEqual(node["username"].InnerText, name[0]);
Assert.AreEqual("Sign out", selenium.GetText(":r6"));
}
catch (AssertionException e)
{
verificationErrors.Append(e.Message);
}
selenium.Click(":r6");
}
}
catch (AssertionException e)
{
verificationErrors.Append(e.Message);
}
}
}
}
Step I run this script:
1.I build that script into DLL
2.I start hub by using command "ant lauch-hub"
3.I start 2 remote controls by using command :
ant -Dport=5566 -Denvironment="*chrome" launch-remote-control
ant -Dport=5577 -Denvironment="*iexplore" launch-remote-control
4.Then I open Nunit and load DLL (code above) and run
5.The NUNit doesnot respond anything.
I think there are some missing things but I dont know.
How can the test script (DLL) know which is sequence of remote control is selected to run the test????
Please help me!!
Thank you so much
Yui.

I do not see [TestFixture] attribute for Class1. May be that is the problem?
I described procedure of executing tests on selenium grid here: http://slmoloch.blogspot.com/2009/12/design-of-selenium-tests-for-aspnet_19.html. and you can download sources of tests here: http://code.google.com/p/design-of-selenium-tests-for-asp-net/

Related

java localstack lambada - how to run lambada and see logs

I am trying to run lambada using localStack and to see the log ...
so thee running class looks like :
public class LambdaLoader implements RequestHandler<Object, String> {
#Override
public String handleRequest(Object input, Context context) {
LambdaLogger logger = context.getLogger();
logger.log("\"started\"");
return "Complete";
}
I am running it
public class LambdaLoaderIT {
#Test
void handleRequest() throws InterruptedException, IOException {
AwsClientBuilder.EndpointConfiguration endpointConfiguration =
new AwsClientBuilder.EndpointConfiguration(
"http://localhost:4566", Regions.US_EAST_1.getName());
AWSLambda lambdaClient = createLambdaClient(endpointConfiguration);
createLambda(lambdaClient);
}
private AWSLambda createLambdaClient(
AwsClientBuilder.EndpointConfiguration endpointConfiguration) {
return AWSLambdaClientBuilder.standard()
.withEndpointConfiguration(endpointConfiguration)
.withCredentials(
new AWSStaticCredentialsProvider(
new BasicAWSCredentials("dummyAccessKey", "dummySecretKey")))
.build();
}
private void createLambda(AWSLambda clientLambda) throws IOException {
CreateFunctionRequest functionRequest = new CreateFunctionRequest();
functionRequest.setHandler("com.ssp.coreTeam.LambdaLoader::handleRequest");
functionRequest.setFunctionName("handleRequest");
functionRequest.setTimeout(900);
functionRequest.setRuntime("java11");
functionRequest.setRole("arn:aws:lambda:us-east-1:000000000000:function:handleRequest");
FunctionCode code = new FunctionCode();
File file = new File("target/my-lambda-0.0.0-SNAPSHOT.jar");
FileInputStream fileInputStream = new FileInputStream(file);
byte[] bytes = IoUtils.toByteArray(fileInputStream);
code.setZipFile(ByteBuffer.wrap(bytes));
functionRequest.setCode(code);
Environment environment = new Environment();
environment.setVariables(Map.of("LAMBDA_ENV","dev"));
functionRequest.setEnvironment(environment);
CreateFunctionResult function = clientLambda.createFunction(functionRequest);
System.out.println(function);
}
in addition, this is how I have configured lambada in the docker-compose file (notice LAMBDA_EXECUTOR=local ):
localstack:
image: 'localstack/localstack'
ports:
- '4566:4566'
environment:
- SERVICES=lambda,ssm
- DEBUG=1
- DATA_DIR=${DATA_DIR- }
- PORT_WEB_UI=${PORT_WEB_UI- }
- LAMBDA_EXECUTOR=local
- KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
- DOCKER_HOST=unix:///var/run/docker.sock
- HOST_TMP_FOLDER=${TMPDIR}
volumes:
- "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
How can I see the logs and what happened there?
You've already set the DEBUG to 1, so the logs are there.
To read them, use the standard Docker Compose facilities for logs. In your case it should be something like:
docker-compose logs localstack
I would also recommend you to use a small library to inject AWS clients in your tests, named aws-junit5. It would greatly simplify your tests. It supports Lambda clients for both AWS Java SDK 1.x and 2.x. The usage is pretty straightforward:
#ExtendWith(Lambda.class)
class AmazonDynamoDBInjectionTest {
#AWSClient(endpoint = Endpoint.class) // Endpoint configuration
private AWSLambda client;
#Test
void test() {
CreateFunctionRequest functionRequest = new CreateFunctionRequest();
functionRequest.setHandler("com.ssp.coreTeam.LambdaLoader::handleRequest");
functionRequest.setFunctionName("handleRequest");
functionRequest.setTimeout(900);
functionRequest.setRuntime("java11");
functionRequest.setRole("arn:aws:lambda:us-east-1:000000000000:function:handleRequest");
FunctionCode code = new FunctionCode();
File file = new File("target/my-lambda-0.0.0-SNAPSHOT.jar");
FileInputStream fileInputStream = new FileInputStream(file);
byte[] bytes = IoUtils.toByteArray(fileInputStream);
code.setZipFile(ByteBuffer.wrap(bytes));
functionRequest.setCode(code);
Environment environment = new Environment();
environment.setVariables(Map.of("LAMBDA_ENV","dev"));
functionRequest.setEnvironment(environment);
// Just use client here, it will be auto-injected!
CreateFunctionResult function = client.createFunction(functionRequest);
// Rest of your test
System.out.println(function);
}
}
There is even an example of CI/CD with GitHub, which is very similar to what you're doing.

How to block popups in cefsharp browser in vb.net project/ NOT c sharp

i have been looking for a while now, i have found a solution in csharp , but i couldn't translate it (implement it in my vb.net app).
My only aim is that when the user clicks a link no popups appear.
thank you for your help.
My vb.net coding skill is beginner level, c sharp no knowledge.
the working solution in c sharp:
using CefSharp;
using CefSharp.WinForms;
namespace popup_cefsharp
{
public partial class frm_main : Form
{
public frm_main()
{
InitializeComponent();
}
//variable
ChromiumWebBrowser chrome, chrome_popup;
private void initialize_browser()
{
try
{
CefSettings settings = new CefSettings();
Cef.Initialize(settings);
//main browser
chrome = new ChromiumWebBrowser(this.txt_url.Text.Trim());
LifespanHandler life = new LifespanHandler();
chrome.LifeSpanHandler = life;
life.popup_request += life_popup_request;
this.pan_container.Controls.Add(chrome);
chrome.Dock = DockStyle.Fill;
//second browser (popup browser)
chrome_popup = new ChromiumWebBrowser("");
this.pan_container_popup.Controls.Add(chrome_popup);
chrome_popup.Dock = DockStyle.Fill;
}
catch (Exception ex)
{
MessageBox.Show("Error in initializing the browser. Error: " + ex.Message);
}
}
private void carregar_popup_new_browser(string url)
{
//open pop up in second browser
chrome_popup.Load(url);
}
private void frm_main_FormClosing(object sender, FormClosingEventArgs e)
{
//close o object cef
Cef.Shutdown();
Application.Exit();
}
private void frm_main_Load(object sender, EventArgs e)
{
//initialize the browser
this.initialize_browser();
}
private void life_popup_request(string obj)
{
//function for open pop up in a new browser
this.carregar_popup_new_browser(obj);
}
}
}
link original post: https://www.codeproject.com/Articles/1194609/Capturing-a-pop-up-window-using-LifeSpanHandler-an
finally found the solution , if anyone is interested
here is the link, you will need to install the cefsharp nuggets packages, add lifespanhandler as a new class, the file is in the link, then copy the method to call the function from the mainform...
cheers...
https://github.com/messi06/vb.net_CefSharp_popup

How to save a file from a windows store app in Unity

I'm making an app in Unity3D for release on the windows store.
It seems you cant write files using the .net streamwriter.
I'd like to save a csv file to a certain location and then later send it to a server using the WWW class.
I found a project which reads a file from the assets folder.
Heres the code for that...
using UnityEngine;
using System;
using System.Collections;
using System.IO;
#if NETFX_CORE
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Streams;
#endif
namespace IOS
{
public class File
{
public static object result;
#if NETFX_CORE
public static async Task<byte[]> _ReadAllBytes(string path)
{
StorageFile file = await StorageFile.GetFileFromPathAsync(path.Replace("/", "\\"));
byte[] fileBytes = null;
using (IRandomAccessStreamWithContentType stream = await file.OpenReadAsync())
{
fileBytes = new byte[stream.Size];
using (DataReader reader = new DataReader(stream))
{
await reader.LoadAsync((uint)stream.Size);
reader.ReadBytes(fileBytes);
}
}
return fileBytes;
}
#endif
public static IEnumerator ReadAllText(string path)
{
#if NETFX_CORE
Task<byte[]> task = _ReadAllBytes(path);
while (!task.IsCompleted)
{
yield return null;
}
UTF8Encoding enc = new UTF8Encoding();
result = enc.GetString(task.Result, 0, task.Result.Length);
#else
yield return null;
result = System.IO.File.ReadAllText(path);
#endif
}
}
}
public class Example : MonoBehaviour
{
private string data;
IEnumerator ReadFile(string path)
{
yield return StartCoroutine(IOS.File.ReadAllText(path));
data = IOS.File.result as string;
}
public void OnGUI()
{
string path = Path.Combine(Application.dataPath, "StreamingAssets/Data.txt");
if (GUILayout.Button("Read file '" + path + "'"))
{
StartCoroutine(ReadFile(path));
}
GUILayout.Label(data == null ? "<NoData>" : data);
}
}
Heres the MSDN docs for serializing with Windows Store apps
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh758325.aspx
I'm wondering how to adapt this to suit my purposes. ie. Write a file to a specific location that I can reference later when I am sending the file via WWW.
The main issue is the location. The Application.dataPath is read only data within the app's package. To write data use Application.persistentDataPath to get a writable location in the application data folder.
Unity provides alternatives to System.IO.File with its UnityEngine.Windows.File object. You can just switch the using between System.IO and UnityEngine.Windows then call File.ReadAllBytes or File.WriteAllBytes regardless of platform.
This is essentially what your code snippit is doing, except that Unity already provides it.

Why this error comes "The plug-in execution failed because no Sandbox Worker processes are currently available"?

I am using an free trial version of online ms crm 2015 just to understand it and
I wrote this plugin with threads int them
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk; // for Iplugin interface
using nonitcompany; // for earlybinding generated by crmsvcuti.exe
using Microsoft.Crm.Sdk; //for stestate requests
using Microsoft.Crm.Sdk.Messages; //for stestate requests
namespace Plugin_on_create_deact_rec
{
public class account_deactivate:IPlugin
{
public static int semaphore0 = 0, semaphore1 = 0, semaphore2 = 0;
public static IPluginExecutionContext context;
public static IOrganizationServiceFactory factory;
public static IOrganizationService service;
public static IServiceProvider serviceProvider_;
public static Entity accounts;
public static SetStateRequest deactivate;
public static SetStateResponse setstate_response;
public void Execute(IServiceProvider serviceProvider)
{
serviceProvider_ = serviceProvider;
ThreadStart _context = new ThreadStart(context_);
ThreadStart _factory = new ThreadStart(factory_);
ThreadStart _execute = new ThreadStart(execute_);
Thread context_t = new Thread(_context);
Thread factory_t = new Thread(_factory);
Thread execute_t= new Thread(_execute);
context_t.Start();
factory_t.Start();
execute_t.Start();
wait(semaphore0);
}
private static void context_()
{
context = (IPluginExecutionContext)serviceProvider_.GetService(typeof(IPluginExecutionContext));
accounts = (Entity)context.InputParameters["Target"];
EntityReference accounts_reference = new EntityReference();
accounts_reference.LogicalName = accounts.LogicalName;
accounts_reference.Id = accounts.Id;
deactivate = new SetStateRequest();
deactivate.EntityMoniker = accounts_reference;
deactivate.State = new OptionSetValue((int)AccountState.Inactive);
deactivate.Status = new OptionSetValue(2);
signal(semaphore1);
}
private static void factory_()
{
factory = (IOrganizationServiceFactory)serviceProvider_.GetService(typeof(IOrganizationServiceFactory));
service = (IOrganizationService)factory.CreateOrganizationService(context.UserId);
signal(semaphore2);
}
private static void execute_()
{
wait(semaphore1);
wait(semaphore2);
setstate_response = (SetStateResponse)service.Execute(deactivate);
signal(semaphore0);
}
private static void wait(int semaphore)
{
while (semaphore == 0)
{
//do nothing
}
semaphore = semaphore - 1;
}
private static void signal(int semaphore)
{
semaphore = semaphore + 1;
}
}
}
i registerd it on create post syncronous mode in accounts entity .
this error come from then after for every sync plugins registered :
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: The plug-in execution failed because no Sandbox Worker processes are currently available. Please try again.
System.ServiceModel.CommunicationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #5CD64A38Detail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
<ErrorCode>-2147204723</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<Message>The plug-in execution failed because no Sandbox Worker processes are currently available. Please try again.
System.ServiceModel.CommunicationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #5CD64A38</Message>
<Timestamp>2015-03-12T13:19:42.5150181Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText>
[PluginProfiler.Plugins: PluginProfiler.Plugins.ProfilerPlugin]
[dc99cb02-b6c8-e411-80eb-c4346bada6b4: Plugin_on_create_deact_rec.account_deactivate: Create of account (Profiler)]
</TraceText>
</OrganizationServiceFault>
can any one tell me what the hell happened to my instance of crm ..

click link with particular text in selenium

I have tried a few things such as this:
IWebDriver driver = new ChromeDriver(#"D:\Selenium");
driver.Navigate().GoToUrl("http://www.bladibla.com");
ReadOnlyCollection<IWebElement> elements = driver.FindElements(By.TagName("a"));
foreach (IWebElement element in elements)
{
if (element.Text.Equals("Bla"))
{
}
Console.WriteLine(element.Text);
}
Including some XPath without success. All I want is click the link represented by this html:
<img src="images/download16.png" alt="Download XYZ" />Bla
Any help would be very much appreciated. Thanks.
PS:
Current code:
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace Selenium
{
class Program
{
static void Main(string[] args)
{
try
{
IWebDriver driver = new ChromeDriver(#"D:\Selenium");
driver.Navigate().GoToUrl("http://www.doogal.co.uk/UKPostcodes.php?Search=AB1");
var test = driver.FindElement(By.CssSelector("a[href^='UKPostcodesKML']"));
driver.Close();
}
catch (Exception e)
{
throw;
}
}
}
}
You can use partial link text like below.
driver.findElement(By.partialLinkText("Bla"))
or
if the href is unique for that anchor, then you can get that specific anchor by using css selector like below.
driver.FindElement(By.CssSelector("a[href=xyz/bla.txt]")
This should work for you:
driver.findElement(By.xpath("//a[contains(text(), 'KML format')]")).click();
Or this:
driver.findElement(By.partialLinkText("KML format")).click();