Below function (Search.py) deals with webpage connection and searching some user provided input and returning the results,It is working fine when I execute the python code as it is in a file.
But the same code when integrated with some other python code (Main.py is the actual function and this search.py has been defined as a function in the same) and triggering that main file execution is from a html code using wampserver is not working
By debugging I see that execution of main function is hanging when this search function is being called.
path="C:\\Python34\\geckodriver.exe"
driver=webdriver.Firefox()
baseUrl="https://" + "XX" + ":" + "YY" + "#" + "somesite.xhtml";
driver.get(baseUrl);
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "frm_searchWordsPanel"))
)
finally:
element.send_keys("To be searched")
resp=driver.find_element_by_id("frm_runFTSbutton").click()
Search_Url=driver.current_url
Search_res=requests.get(Search_Url , auth=HTTPBasicAuth(userName, passWord))
Search_soup = BeautifulSoup(Search_res.content,'html.parser')
for link in Search_soup.find_all('a'):
if (str(link.get('href')).startswith('https')):
result=result+link.get('href')+'\r'+'\n'
driver.close()
return(result)
Related
This question already has answers here:
Logging Messages from Java Class back to the Karate Report
(3 answers)
Closed 1 year ago.
I want to be able to write log statements, that get added to the karate.log file as well as to the Cucumber Reports that get generated when using standalone karate.jar.
When I use karate.log from a javascript function it only adds the log statement to the karate.log file and not the cucumber report.
I have also tried to do this from a java function as well by using both slf4j logger as well as the com.intuit.karate.Logger class. However both of these only add logs to the karate.log file and not to the cucumber reports.
I need this because I am writing some common code for which I don't want my QA-Engineers to write * print <> statements in the karate feature files.
I also looked at the com.intuit.karate.core.ScriptBridge.log(Object... objects) method which is what I am assuming gets called when you call karate.log(..), it looks like it should work, but it isn't working for me.
I am using karate-0.9.4, and here's what my karate-config.js looks like
function conf() {
var env = karate.env // set the environment that is to be used for executing the test scripts
var host = '<some-host-name>';
var port = '443';
var protocol = 'https';
var basePath = java.lang.System.getenv('GOPATH') + '/src/karate-tests';
// a custom 'intelligent' default
if (!env) {
env = 'dev';
}
var applicationURL = ((!port || port == '') || (port == '80' && protocol == 'http') || (port == '443' && protocol == 'https'))
? protocol + '://' + host
: protocol + '://' + host + ":" + port;
// Fail quickly if there is a problem establishing connection or if server takes too long to respond
karate.configure('connectTimeout', 30000);
karate.configure('readTimeout', 30000);
// pretty print request and response
//karate.configure('logPrettyRequest', true);
//karate.configure('logPrettyResponse', true);
karate.configure('printEnabled', true);
// do not print steps starting with * in the reports
//karate.configure('report',{showLog: true, showAllSteps: true });
// Turn off SSL certificate check
karate.configure('ssl', true);
var config = {
env: env,
appBaseURL: applicationURL,
sharedBasePath: basePath
};
karate.log("config.sharedBasePath = ", config.sharedBasePath)
karate.log('karate.env = ', config.env);
karate.log('config.appBaseURL = ', config.appBaseURL);
return config
}
This is because of a bug in karate-0.9.4 which seems to be partially fixed in karate-0.9.5.RC4 release. I have opened a ticket for it on GitHub - https://github.com/intuit/karate/issues/975
I just tried this in 0.9.5.RC4. If you are looking for something more than this - it needs a change in Karate. You are welcome to contribute. I have to say that I'm surprised (and somewhat annoyed) to see these requests. Why are you so concerned about pretty reports instead of focusing on testing. I'd like you to think about it.
This other discussion may be a related reference: https://github.com/intuit/karate/issues/951 | https://github.com/intuit/karate/issues/965
If you really want to pursue this, you can look at the "hook" interceptor mentioned in this comment: https://github.com/intuit/karate/issues/970#issuecomment-557443551
So in void afterStep(StepResult result, ScenarioContext context); - you can modify the StepResult by calling appendToStepLog(String log).
EDIT: other references:
https://stackoverflow.com/a/57079152/143475
https://stackoverflow.com/a/47366897/143475
Script failing on Browserstack (intermittently).
Using serenity-bdd , and executing on browserstack....
DesiredCapabilities capabilities = new DesiredCapabilities();
if (MyDriverClass.deviceType.equalsIgnoreCase("Tablet")) {
capabilities.setCapability("os_version", "8.0");
capabilities.setCapability("device", "Samsung Galaxy Tab S3");
capabilities.setCapability("real_mobile", "true");
capabilities.setCapability("browserstack.platform",
"ANDROID");
capabilities.setCapability("project", "Tablet_PROJECT");
capabilities.setCapability("browserstack.browser", "chrome");
capabilities.setCapability("browserstack.browser_version", "76.0");
//also used appium version 1.6.5
capabilities.setCapability("browserstack.appium_version", "1.7.1");
capabilities.setCapability("deviceOrientation", orientation);
capabilities.setCapability("browserstack.local", browserstackLocal);
capabilities.setCapability("browserstack.localIdentifier",
browserstackLocalIdentifier);
capabilities.setCapability("browserstack.debug", true);
capabilities.setCapability("browserstack.video", true);
capabilities.setCapability("build", browserStackTCBuild);
return new RemoteWebDriver(
new URL("https://" + username + ":" + accessKey + "#hub-
cloud.browserstack.com/wd/hub"),`enter code here`
capabilities);
I am not sure why getting server side error. Even all the script relate elements and locator is on the page and in view.
The error unknown server-side error is generally encountered when the element you are trying to locate is hidden/ not visible.
You will need to ensure that the element you are trying to locate is in the viewport and nothing is overlaying it. You can read more on the exact causes for the above error here.
Can anyone point me to the best way to use option(error = function(...){}) properly? I want to write errors to a log file and then terminate as usually. Currently I use
options(error = function(...) {
#... write to logfile ...
options(error = NULL)
stop(geterrmessage())
})
But resetting the option and calling stop() again looks like a hack to me. I also tried q("no", status = 1, runLast = FALSE) (as from the documentation of stop()), but this does not seem to be equivalent to a normal stop(). For example, in RStudio server it quits the whole session.
I need to use the option() instead of tryCatch() because I want to catch all possible errors that occur in the script. I launch my script via a cron job, and I want to get an email/log entry as soon as the script fails.
A tryCatch block would probably be the best option for this type of situation.
tryCatch({
#... main code to run ...
}, warning = function(w) {
#... code to run if any warnings occur ...
warning(w) # Show the warning
}, error = function(e) {
#... write to log file ...
stop(e) # Stop script and show error message. Delete this line if you do not want to stop script
}, finally = {
#... code to run whether or not error occurs ...
})
I'm having trouble writing to the console from an MSpec assertion. I'm using v0.5.11 (unsigned) from Nuget. Nothing radical here, but it's not working. Anyone know what I'm missing?
public class When_doing_stuff
{
It should_out_stuff_to_console = () =>
{
var val1 = 1;
var val2 = 2;
(val1 + val2).ShouldEqual(3);
Console.WriteLine(val2);
};
}
I suspect that you actually have a failing assertion in your real code. You posted a passing assertion, which should print just fine (as Alexander and I have both verified locally).
A failing assertion, however, throws a SpecificationException and the Console line would never be executed. You should print before your assertion. For example
It should_out_stuff_to_console = () =>
{
Console.WriteLine(val2);
(val1 + val2).ShouldEqual(3);
}
And the output from the mspec command line runner
cmd> mspec-clr4.exe test.dll
Specs in test:
When doing stuff
Blah
» should out stuff to console
But, I don't recommend printing debug statements to the console from your assertions, or your test run in general. It's going to gum up the test report (as you can see above).
In fact there's nothing wrong with the assertion here, Anthony :-)
I pasted the code user287079 posted into a new Class Library, see what's being printed in my console:
>mspec-clr4 <somewhere>\bin\Debug\ClassLibrary1.dll
Specs in ClassLibrary1:
When doing stuff
2
» should out stuff to console
Contexts: 1, Specifications: 1, Time: 0.11 seconds
I'm trying to make a HTTP request from a Adobe Illustrator Script (this question is not really JSX-related, though) via BridgeTalk to a local Rails app using a Socket connection (as you you see — plenty that could go wrong ;) ).
Finally managed to get a request through, but the Rails app throws an error:
ERROR bad Request-Line `GET /test.json HTTP/1.1'.
Currently no special headers are sent — the set–up is pretty simple:
var connection = new Socket;
var response = '';
var host = '127.0.0.1:3000';
var path = '/test.json';
var method = 'GET';
var request = method + " " + path + " HTTP/1.1";
if (connection.open(host)) {
connection.write(request);
response = connection.read(999999);
} else {
$.writeln('Socket connection failed.');
}
connection.close();
I'm assuming that the request is illformed, but I'm not sure what's expected.
The Rails app runs on WEBrick.
Any help or hint on what Rails expects here, would be greatly appreciated.
Update
It seems that WEBrick expects a carriage return in the end of the request line: \r\n .
Unfortunately I’m using BridgeTalk to execute a piece of code within Bridge which requires me to use uneval() or toSource() on the function mentioned above. These seem to escape backslashes, converting
GET /test.json HTTP/1.1\r\n
into
GET /test.json HTTP/1.1\\r\\n
causing the same error.
Any ideas?
Took a while until I got this figured out, but as usual — “too many moving parts are making it hard to spot the problem”:
Defining the request using the encoded version of the carriage return and decoding on destination will help:
var request = decodeURI(method + " " + path + " HTTP/1.1%0d%0a");
However, it turns out that a proper request should end in \n\n not \r\n, so make this:
var request = decodeURI(method + " " + path + " HTTP/1.1%0a%0a");
Now the requests come through and now longer throw errors.