Appium: App Path only works with a direct link? - appium

I'm using Laravel php and Appium.
I want Appium to download the .apk/.ipa file from a certain route which returns the downloaded file.
App path in Appium: localhost/downloadApp
public function downloadApp(Request $request) {
...
return response()->download($path);
}
If I try this way, it doesn't work and I get an error "[Support] Error: Plist file doesn't exist: '.../Info.plist". I don't know why because if I call localhost/downloadApp in my browser, it downloads the file.
But if I use the direct link (http://localhost/uploads/HelloWorld.ipa) in Appium, it works.

The path must point to an actual file.
You can download the file itself from your code but you need to make sure that:
The file has completed to download before you set up the driver
The path to the downloaded file is correct, make sure the name of the file and the download location is the same as what you set in the capabilities ("localhost/downloadApp" doesn't seem like the correct download path)

I have the same problem, I just use return redirect ($file_path); and that works fine for apk file. For security, I also use the POST method to start download. This is my code:
//blade code :
<li class="nav-item">
<form method="POST" action="{{url('/files/download')}}">
{{ csrf_field()}}
<button class="btn btn-primary fa fa-download"> download </button>
</form>
</li>
//Route code :
Route::post('/files/download', 'FilesController#download');
//Controller code :
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\File;
use App\Http\Controllers\Controller;
class FilesController extends Controller
{
public function download($file)
{
$file_path = 'your folder path/file.apk';
// if your file in public use $path = "/your folder/file.apk"
// if your file is in out of public you may use two points like that: $path = "../your folder/file.apk"
return redirect ($file_path);
}
}

Related

Swashbuckle.AspNetCore + Blazor - Dynamically Add/Remove custom .css file at runtime

I have Blazor Webassembly ASP.NET Core hosted and I installed Swashbuckle.AspNetCore to display endpoints that my Blazor app has (/swagger endpoint).
My Startup.Configure looks like this (only swagger part):
app.UseSwagger();
app.UseSwaggerUI(c =>
{
foreach (var description in provider.ApiVersionDescriptions)
{
c.SwaggerEndpoint($"{description.GroupName}/swagger.json", $"v{description.GroupName.ToUpperInvariant()}");
}
c.InjectStylesheet("/css/swaggerDark.css");
});
As you can see, I inject custom .css file which works.
In my Blazor app, I inject swagger so my page looks like this (.razor page):
<iframe src="swagger"/>
Again, it works correctly, swagger documentation is displayed and it has dark theme.
I have noticed (to no suprise) that this iframe has a link to this .css file:
<link href="/css/swaggerDark.css" rel="stylesheet" media="screen" type="text/css">
Removing this link brings the default swagger look (light theme).
The user of my app can choose which theme he wants (light/dark) of the whole application. My question is, how do I dynamically inject/remove (or maybe enable/disable) this .css file so depending on which app theme the user chooses, the swagger will either display default (light) or dark theme (using that .css file)?
I couldn't find any relevant info on this issue so I decided to create this question. I appreciate any help. Thank you.
Ok, I figured it out. The answer is: use JsInterop.
My .razor page looks like this at the moment:
#page "/something"
#inject IJSRuntime JS //needed to call InvokeVoidAsync
//I made my own ThemeManager to control the Blazor app theme
#if (ThemeManager.IsDefaultTheme)
{
<iframe id="myiframe" src="swagger" #onload="() => ToggleSwaggerTheme(true)" />
}
else
{
<iframe id="myiframe" src="swagger" #onload="() => ToggleSwaggerTheme(false)" />
}
#code {
private async Task ToggleSwaggerTheme(bool isLight) => await JS.InvokeVoidAsync("toggleSwaggerTheme", isLight);
}
I made it so the iframe toggles depending on the app theme. The ToggleSwaggerTheme function is self-explanatory - I'm calling my JS function to toggle the theme of swagger.
In index.html I added a script to load my helperFunctions.js (in body) in which toggleSwaggerTheme function can be found:
<script src="/js/helperFunctions.js"></script>
I added helperFunctions.js in my wwwroot:
wwwroot -> js -> helperFunctions.js
My helperFunctions.js looks like this:
function toggleSwaggerTheme(isLight) {
let myiframe = document.getElementById('myiframe');
let styleSheets = myiframe.contentWindow.document.styleSheets;
for (let i = 0; i < styleSheets.length; i++) {
if (styleSheets[i].href == null) {
continue;
}
if (styleSheets[i].href.includes("/css/swaggerDark.css")) {
styleSheets[i].disabled = isLight;
break;
}
}
}
The above function allowed me to toggle the swagger theme. Please note, I don't know if this is the best solution that can be created. Also, I'm not sure how it's going to behave in the production environment. I will update this answer if there are any problems in the production. I hope it can help somebody.
UPDATE AFTER GOING LIVE:
I've had some issues with displaying dark theme after going live. But the following seems to fix the issue:
In Program.cs (Server side), in CreateHostBuilder method I added (not sure if it's needed):
webBuilder.UseStaticWebAssets();
So in my case, it looks like this:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStaticWebAssets();
webBuilder.UseStartup<Startup>();
});
I also changed my swaggerDark.css file property: the Copy to Output Directory to Copy always.
You do this by right-clicking the file in Solution Explorer -> Properties (at the end).
After doing these new steps, It seems to be working fine. I hope it can help somebody.

Intra-page link starts at URL root

This is so simple I don't get how it could possibly go wrong. I'm trying to get a simple intra-page link to behave.
(If it's relevant, this is an angular 2 app, using routing.)
Here is a typical page:
Skip to main content
<div class="page-body">
<main>
<div class="content-body" id="content-start">
<h1>Employee Search</h1>
</div>
<main>
</div>
The URL of this page (in my dev env) is
http://localhost:49974/app/employee/search
When I click (or focus then press enter) on Skip to main content it should go to
http://localhost:49974/app/employee/search#content-start
but instead goes to
http://localhost:49974/app#content-start
(and then immediately switches to
http://localhost:49974/app/#content-start
)
I can't have messed up the linking itself; this must have something to do with how the routing is working.
It looks like I have to do it this way:
<a href="app/request/timeoff#content-start">
But that doesn't seem correct.
I don't know if this is a the correct way, or the angular way, but it works:
app.component.html:
Skip to main content
app.component.ts
export class AppComponent {
pageURL: string;
ngDoCheck() {
this.pageURL = window.location.href;
var link = this.pageURL.indexOf('#content-start');
if (link > -1) {
console.log(this.pageURL.substring(0, link));
this.pageURL = this.pageURL.substring(0, link);
}
}
}
every-page.html:
<h1 class="content-body" id="content-start">Page</h1>
Not sure if ngDoCheck is the appropriate event use.
Full disclosure: app.component is a wrapper - with header and the 'skip to content' link that contains all the pages and their content.
So, the logic for the 'skip to content' link exists once, while the actual content target #content-start lives in the top of each content page.

Froala editor images absolute url path configuration

I was wondering if there's any option that after image upload the image source will be <img src="/uploads/image.jpg" /> rather than <img src="http://example.com/uploads/image.jpg" />?
I can't find it anything about this and I have lots of content that it's added on localhost and when I upload it to production I'll have to manually change the links
Any suggestions?
Perhaps can you try to find/replace when image inserted. Something like this :
$(".selector").on('editable.imageInserted', function (e, editor, img) {
var source = img.replace('www.host.com','');
$('.img_class').attr('src',source);
});
I found the solutions as answered by the creator of froala https://github.com/froala/wysiwyg-editor/issues/445
Thanks
Easiest way to do this is using Froala's image server upload example and simply adding the domain at the beginning of the link
<?php
// Include the editor SDK.
require '/path/to/wysiwyg-editor-php-sdk-master/lib/FroalaEditor.php';
// Store the image.
try {
$response = FroalaEditor_Image::upload('/path/to/upload/');
$response->link = "https://www.example.com" . $response->link;
echo stripslashes(json_encode($response));
}
catch (Exception $e) {
http_response_code(404);
}
?>

I have to download image, pdf or docs file in mvc3

This is my code. I have written in MVC3 to download image file, *.pdf file or *.docx file on click.
Variable agreefile defined in foreach loop store path of image file, pdf file and word file. Now I want to download items when user clicks on any item from my view page.
#foreach (string agreefile in Model.SAgreement)
{
<div style="width:100px;height:150px;display:inline-block;margin:10px 5px;">
#*<img src="#agreefile" style="height:150px; width:100px" alt=""/>*#
<object data=#agreefile" type="application/docx" width="300" height="200">
alt : test
</object>
</div>
}
The solution would be to have a button that triggers an action on the controller that returns a file. (you need to change the mime type depending on what you are returning)
Something like this:
public ActionResult GetFile()
{
//...
return File(filePath, "application/pdf", fileDownloadName);
}

Icons for each file type

In my MVC application, user can upload various type of files (pdf, jpg, txt etc) and I want to show icon specific to each type, currently I am using one icon (pdf) for the purpose, I want, that based on the file type, associated icon should be displayed. Please guide me what kind of approach I can use for this purpose
<td>
#if (item.CalibratedBy != null){
<a href = #Url.Action("ViewCertificate", new { fileName = item.CalibrationCert }) >
<img src = "#Url.Content("~/Content/Icons/pdf.jpg")" alt = "attachment" /> </a>
}
</td>
Expose the extension type needed as a property on item (presumably being passed in through the Model)
Create an HtmlHelper extension method that will take in item.FileType and return the path to the appropriate icon file to be used. Call this in your <img> tag.

Resources